--- old/src/java.base/share/classes/java/lang/ClassLoader.java 2014-10-16 10:36:56.143856873 +0200
+++ new/src/java.base/share/classes/java/lang/ClassLoader.java 2014-10-16 10:36:56.029858879 +0200
@@ -29,12 +29,10 @@
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessController;
import java.security.AccessControlContext;
import java.security.CodeSource;
-import java.security.Policy;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
@@ -54,7 +52,6 @@
import sun.misc.CompoundEnumeration;
import sun.misc.Resource;
import sun.misc.URLClassPath;
-import sun.misc.VM;
import sun.reflect.CallerSensitive;
import sun.reflect.Reflection;
import sun.reflect.misc.ReflectUtil;
@@ -356,7 +353,17 @@
* If the class was not found
*/
public Class> loadClass(String name) throws ClassNotFoundException {
- return loadClass(name, false);
+ try {
+ return loadClass(name, false);
+ } catch (ClassNotFoundException e) {
+ if (e.getStackTraceDepth() > 0) {
+ // we've got an exception with stack trace - rethrow it
+ throw e;
+ } else {
+ // we've got a stack-less exception - replace it
+ throw new ClassNotFoundException(e.getMessage(), e.getException());
+ }
+ }
}
/**
@@ -529,7 +536,11 @@
* @since 1.2
*/
protected Class> findClass(String name) throws ClassNotFoundException {
- throw new ClassNotFoundException(name);
+ throw new ClassNotFoundException(
+ name + " (thrown by: " + getClass().getName() + ")",
+ null,
+ false
+ );
}
/**
--- old/src/java.base/share/classes/java/lang/ClassNotFoundException.java 2014-10-16 10:36:56.542849849 +0200
+++ new/src/java.base/share/classes/java/lang/ClassNotFoundException.java 2014-10-16 10:36:56.415852085 +0200
@@ -97,6 +97,21 @@
}
/**
+ * Constructs a ClassNotFoundException
with the
+ * specified detail message, optional exception that was
+ * raised while loading the class and a writableStackTrace flag.
+ *
+ * @param s the detail message
+ * @param ex the exception that was raised while loading the class
+ * @param writableStackTrace whether or not the stack trace should
+ * be writable and filled-in
+ */
+ ClassNotFoundException(String s, Throwable ex, boolean writableStackTrace) {
+ super(s, null, true, writableStackTrace);
+ this.ex = ex;
+ }
+
+ /**
* Returns the exception that was raised if an error occurred while
* attempting to load the class. Otherwise, returns null.
*
--- old/src/java.base/share/classes/java/lang/ReflectiveOperationException.java 2014-10-16 10:36:56.824844885 +0200
+++ new/src/java.base/share/classes/java/lang/ReflectiveOperationException.java 2014-10-16 10:36:56.737846417 +0200
@@ -88,4 +88,23 @@
public ReflectiveOperationException(Throwable cause) {
super(cause);
}
+
+ /**
+ * Package-private constructor that enables all control on the construction
+ * of exception object.
+ *
+ * @param message the detail message.
+ * @param cause the cause. (A {@code null} value is permitted,
+ * and indicates that the cause is nonexistent or unknown.)
+ * @param enableSuppression whether or not suppression is enabled
+ * or disabled
+ * @param writableStackTrace whether or not the stack trace should
+ * be writable
+ */
+ ReflectiveOperationException(String message,
+ Throwable cause,
+ boolean enableSuppression,
+ boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ }
}
--- old/src/java.base/share/classes/java/net/URLClassLoader.java 2014-10-16 10:36:57.147839200 +0200
+++ new/src/java.base/share/classes/java/net/URLClassLoader.java 2014-10-16 10:36:57.032841224 +0200
@@ -42,7 +42,6 @@
import java.util.Enumeration;
import java.util.List;
import java.util.NoSuchElementException;
-import java.util.Objects;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.jar.Attributes;
@@ -378,7 +377,9 @@
throw (ClassNotFoundException) pae.getException();
}
if (result == null) {
- throw new ClassNotFoundException(name);
+ // super method is ClassLoader.findClass() which
+ // always throws stack-less exception
+ return super.findClass(name);
}
return result;
}