Applications that perform the following steps fail with an inaccurate
exception in JDK-FCS:
1. Use the default security policy (i.e. lack the ability to read all
system properties).
2. Try to read inaccessible system properties in the static
initializer of a given class.
Users expect to receive an ExceptionInInitializerError error, instead
they get a NoClassDefFoundError.
Exception that occurs with java full version "JDK-1.2fcs-D":
============================================================
cycler:exceptionInInit:\> java ExceptionInInit
This program should exit with an exception in initializer error not with a class not found error.
Exception in thread "main" java.lang.NoClassDefFoundError: ExceptionInInit$Test
at ExceptionInInit$Test.showTest(Compiled Code)
at ExceptionInInit.main(Compiled Code)
Exception that occurred with java full version "JDK-1.2beta4-K":
============================================================
cycler:exceptionInInit:\> java ExceptionInInit
This program should exit with an exception in initializer error not with a class not found error.
Exception in thread "main" java.lang.ExceptionInInitializerError: java.security.AccessControlException: access denied (java.util.PropertyPermission test.src read)
at java.security.AccessControlContext.checkPermission(Compiled Code)
at java.security.AccessController.checkPermission(Compiled Code)
at java.lang.SecurityManager.checkPermission(Compiled Code)
at java.lang.SecurityManager.checkPropertyAccess(Compiled Code)
at java.lang.System.getProperty(Compiled Code)
at sun.security.action.GetPropertyAction.run(Compiled Code)
at java.security.AccessController.doPrivileged(Native Method)
at ExceptionInInit$Test.<clinit>(ExceptionInInit.java:33)
at ExceptionInInit.main(Compiled Code)
This problem does not arise by simply throwing a new
AccessControlException in the static initializer of a given class. It
only resulted from an attempt to read an inaccessible property.
I have included a simple test case which demonstrates the problem
outlined above:
============================================================
/* Simple test case to demonstrate the unexpected/erroneous exception
* thrown by a java application that tries to read a system property
* in a static initializer (but does not have permission to do so).
*/
import java.io.PrintStream;
public class ExceptionInInit {
public static void main(String[] args) {
Test test = null;
System.err.println("This program should exit with an exception " +
"in initializer error not with a class " +
"not found error.\n");
System.setSecurityManager(new java.rmi.RMISecurityManager());
Test.showTest();
}
public static class FooBar {
static String test = "test";
FooBar(String test) {
this.test = test;
}
}
public static class Test extends FooBar {
/*
* An AccessControlException is thrown in the static initializer of the class
* FooBar. This exception should produce an ExceptionInInitializer error. Instead
* it causes a more cryptic ClassNotFound error.
*
* The following is an excerpt from the output from java.security.debug=all
*
* access: access denied (java.util.PropertyPermission test.src read)
* java.lang.Exception: Stack trace
* at java.lang.Thread.dumpStack(Thread.java:938)
* at java.security.AccessControlContext.checkPermission(AccessControlContext.java:184)
* at java.security.AccessController.checkPermission(AccessController.java:402)
* at java.lang.SecurityManager.checkPermission(SecurityManager.java:516)
* at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1035)
* at java.lang.System.getProperty(System.java:441)
* at sun.security.action.GetPropertyAction.run(GetPropertyAction.java:73)
* at java.security.AccessController.doPrivileged(Native Method)
* at ExceptionInInit$Test.<clinit>(ExceptionInInit.java:33)
* at ExceptionInInit.main(ExceptionInInit.java:18)
* access: domain that failed ProtectionDomain (file:/tmp/exceptionInInit/ <no certificates>)
*
* The following exception is occurring when this test program tries
* to access the test.src property.
*/
private static String test = (String) java.security.
AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("test.src", "."));
Test(String test) {
super(test);
}
public static void showTest() {
System.err.println(test);
}
}
}
exception in JDK-FCS:
1. Use the default security policy (i.e. lack the ability to read all
system properties).
2. Try to read inaccessible system properties in the static
initializer of a given class.
Users expect to receive an ExceptionInInitializerError error, instead
they get a NoClassDefFoundError.
Exception that occurs with java full version "JDK-1.2fcs-D":
============================================================
cycler:exceptionInInit:\> java ExceptionInInit
This program should exit with an exception in initializer error not with a class not found error.
Exception in thread "main" java.lang.NoClassDefFoundError: ExceptionInInit$Test
at ExceptionInInit$Test.showTest(Compiled Code)
at ExceptionInInit.main(Compiled Code)
Exception that occurred with java full version "JDK-1.2beta4-K":
============================================================
cycler:exceptionInInit:\> java ExceptionInInit
This program should exit with an exception in initializer error not with a class not found error.
Exception in thread "main" java.lang.ExceptionInInitializerError: java.security.AccessControlException: access denied (java.util.PropertyPermission test.src read)
at java.security.AccessControlContext.checkPermission(Compiled Code)
at java.security.AccessController.checkPermission(Compiled Code)
at java.lang.SecurityManager.checkPermission(Compiled Code)
at java.lang.SecurityManager.checkPropertyAccess(Compiled Code)
at java.lang.System.getProperty(Compiled Code)
at sun.security.action.GetPropertyAction.run(Compiled Code)
at java.security.AccessController.doPrivileged(Native Method)
at ExceptionInInit$Test.<clinit>(ExceptionInInit.java:33)
at ExceptionInInit.main(Compiled Code)
This problem does not arise by simply throwing a new
AccessControlException in the static initializer of a given class. It
only resulted from an attempt to read an inaccessible property.
I have included a simple test case which demonstrates the problem
outlined above:
============================================================
/* Simple test case to demonstrate the unexpected/erroneous exception
* thrown by a java application that tries to read a system property
* in a static initializer (but does not have permission to do so).
*/
import java.io.PrintStream;
public class ExceptionInInit {
public static void main(String[] args) {
Test test = null;
System.err.println("This program should exit with an exception " +
"in initializer error not with a class " +
"not found error.\n");
System.setSecurityManager(new java.rmi.RMISecurityManager());
Test.showTest();
}
public static class FooBar {
static String test = "test";
FooBar(String test) {
this.test = test;
}
}
public static class Test extends FooBar {
/*
* An AccessControlException is thrown in the static initializer of the class
* FooBar. This exception should produce an ExceptionInInitializer error. Instead
* it causes a more cryptic ClassNotFound error.
*
* The following is an excerpt from the output from java.security.debug=all
*
* access: access denied (java.util.PropertyPermission test.src read)
* java.lang.Exception: Stack trace
* at java.lang.Thread.dumpStack(Thread.java:938)
* at java.security.AccessControlContext.checkPermission(AccessControlContext.java:184)
* at java.security.AccessController.checkPermission(AccessController.java:402)
* at java.lang.SecurityManager.checkPermission(SecurityManager.java:516)
* at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1035)
* at java.lang.System.getProperty(System.java:441)
* at sun.security.action.GetPropertyAction.run(GetPropertyAction.java:73)
* at java.security.AccessController.doPrivileged(Native Method)
* at ExceptionInInit$Test.<clinit>(ExceptionInInit.java:33)
* at ExceptionInInit.main(ExceptionInInit.java:18)
* access: domain that failed ProtectionDomain (file:/tmp/exceptionInInit/ <no certificates>)
*
* The following exception is occurring when this test program tries
* to access the test.src property.
*/
private static String test = (String) java.security.
AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("test.src", "."));
Test(String test) {
super(test);
}
public static void showTest() {
System.err.println(test);
}
}
}
- duplicates
-
JDK-4167764 (jit) Catch clause does not catch exceptions under certain conditions.
-
- Closed
-