src/share/classes/java/lang/Class.java

Print this page

        

@@ -347,11 +347,12 @@
                                 return null;
                             }
                         });
                 cachedConstructor = c;
             } catch (NoSuchMethodException e) {
-                throw new InstantiationException(getName());
+                throw (InstantiationException)
+                    new InstantiationException(getName()).initCause(e);
             }
         }
         Constructor<T> tmpConstructor = cachedConstructor;
         // Security check (same as in java.lang.reflect.Constructor)
         int modifiers = tmpConstructor.getModifiers();

@@ -971,11 +972,12 @@
                 // the immediately enclosing method or constructor's
                 // descriptor (null iff name is).
                 descriptor      = (String)   enclosingInfo[2];
                 assert((name != null && descriptor != null) || name == descriptor);
             } catch (ClassCastException cce) {
-                throw new InternalError("Invalid type in enclosing method information");
+                throw (InternalError)
+                    new InternalError("Invalid type in enclosing method information").initCause(cce);
             }
         }
 
         boolean isPartial() {
             return enclosingClass == null || name == null || descriptor == null;

@@ -1237,11 +1239,12 @@
             return null;
         // Otherwise, strip the enclosing class' name
         try {
             return getName().substring(enclosingClass.getName().length());
         } catch (IndexOutOfBoundsException ex) {
-            throw new InternalError("Malformed class name");
+            throw (InternalError)
+                new InternalError("Malformed class name").initCause(ex);
         }
     }
 
     /**
      * Returns {@code true} if this is a local class or an anonymous

@@ -2952,13 +2955,12 @@
                         });
                 enumConstants = (T[])values.invoke(null);
             }
             // These can happen when users concoct enum-like classes
             // that don't comply with the enum spec.
-            catch (InvocationTargetException ex) { return null; }
-            catch (NoSuchMethodException ex) { return null; }
-            catch (IllegalAccessException ex) { return null; }
+            catch (InvocationTargetException | NoSuchMethodException |
+                   IllegalAccessException ex) { return null; }
         }
         return enumConstants;
     }
     private volatile transient T[] enumConstants = null;