DynamicJava allows classes to be created in arbitrary packages, but doesn't cleanly handle errors when adding to a package is not allowed. Example:
> package misc;
> class Foo {}
> Foo.class
class misc.Foo
> package java.lang;
> class Mom {}
> Mom.class
[error occurs]
Stack trace:
edu.rice.cs.util.UnexpectedException: java.lang.SecurityException: Prohibited package name: java.lang
at edu.rice.cs.drjava.model.repl.newjvm.MainJVM$ResultHandler.forUnexpectedException(MainJVM.java:794)
at edu.rice.cs.drjava.model.repl.newjvm.MainJVM$ResultHandler.forUnexpectedException(MainJVM.java:748)
at edu.rice.cs.drjava.model.repl.newjvm.InterpretResult$UnexpectedExceptionResult.apply(InterpretResult.java:95)
at edu.rice.cs.drjava.model.repl.newjvm.MainJVM.interpret(MainJVM.java:190)
at edu.rice.cs.drjava.model.repl.RMIInteractionsModel._interpret(RMIInteractionsModel.java:75)
at edu.rice.cs.drjava.model.repl.InteractionsModel.interpret(InteractionsModel.java:222)
at edu.rice.cs.drjava.model.repl.InteractionsModel$1$1.run(InteractionsModel.java:199)
at java.lang.Thread.run(Thread.java:637)
Caused by: java.lang.SecurityException: Prohibited package name: java.lang
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:534)
at java.lang.ClassLoader.defineClass(ClassLoader.java:669)
at java.lang.ClassLoader.defineClass(ClassLoader.java:520)
at edu.rice.cs.dynamicjava.interpreter.TreeClassLoader.loadTree(TreeClassLoader.java:49)
at edu.rice.cs.dynamicjava.symbol.TreeClass$1.value(TreeClass.java:70)
at edu.rice.cs.dynamicjava.symbol.TreeClass$1.value(TreeClass.java:69)
at edu.rice.cs.plt.lambda.LazyThunk.value(LazyThunk.java:54)
at edu.rice.cs.dynamicjava.symbol.TreeClass.load(TreeClass.java:225)
at edu.rice.cs.dynamicjava.symbol.ExtendedTypeSystem$16$1.value(ExtendedTypeSystem.java:636)
at edu.rice.cs.dynamicjava.symbol.ExtendedTypeSystem$16$1.value(ExtendedTypeSystem.java:635)
at edu.rice.cs.dynamicjava.interpreter.ExpressionEvaluator.visit(ExpressionEvaluator.java:136)
at koala.dynamicjava.tree.TypeExpression.acceptVisitor(TypeExpression.java:100)
at edu.rice.cs.dynamicjava.interpreter.ExpressionEvaluator.value(ExpressionEvaluator.java:39)
at edu.rice.cs.dynamicjava.interpreter.StatementEvaluator.visit(StatementEvaluator.java:103)
at edu.rice.cs.dynamicjava.interpreter.StatementEvaluator.visit(StatementEvaluator.java:29)
at koala.dynamicjava.tree.ExpressionStatement.acceptVisitor(ExpressionStatement.java:106)
at edu.rice.cs.dynamicjava.interpreter.Interpreter.evaluate(Interpreter.java:87)
at edu.rice.cs.dynamicjava.interpreter.Interpreter.interpret(Interpreter.java:48)
at edu.rice.cs.drjava.model.repl.newjvm.InterpreterJVM.interpret(InterpreterJVM.java:251)
at edu.rice.cs.drjava.model.repl.newjvm.InterpreterJVM.interpret(InterpreterJVM.java:228)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
... 1 more
Caused by:
java.lang.SecurityException: Prohibited package name: java.lang
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:534)
at java.lang.ClassLoader.defineClass(ClassLoader.java:669)
at java.lang.ClassLoader.defineClass(ClassLoader.java:520)
at edu.rice.cs.dynamicjava.interpreter.TreeClassLoader.loadTree(TreeClassLoader.java:49)
at edu.rice.cs.dynamicjava.symbol.TreeClass$1.value(TreeClass.java:70)
at edu.rice.cs.dynamicjava.symbol.TreeClass$1.value(TreeClass.java:69)
at edu.rice.cs.plt.lambda.LazyThunk.value(LazyThunk.java:54)
at edu.rice.cs.dynamicjava.symbol.TreeClass.load(TreeClass.java:225)
at edu.rice.cs.dynamicjava.symbol.ExtendedTypeSystem$16$1.value(ExtendedTypeSystem.java:636)
at edu.rice.cs.dynamicjava.symbol.ExtendedTypeSystem$16$1.value(ExtendedTypeSystem.java:635)
at edu.rice.cs.dynamicjava.interpreter.ExpressionEvaluator.visit(ExpressionEvaluator.java:136)
at koala.dynamicjava.tree.TypeExpression.acceptVisitor(TypeExpression.java:100)
at edu.rice.cs.dynamicjava.interpreter.ExpressionEvaluator.value(ExpressionEvaluator.java:39)
at edu.rice.cs.dynamicjava.interpreter.StatementEvaluator.visit(StatementEvaluator.java:103)
at edu.rice.cs.dynamicjava.interpreter.StatementEvaluator.visit(StatementEvaluator.java:29)
at koala.dynamicjava.tree.ExpressionStatement.acceptVisitor(ExpressionStatement.java:106)
at edu.rice.cs.dynamicjava.interpreter.Interpreter.evaluate(Interpreter.java:87)
at edu.rice.cs.dynamicjava.interpreter.Interpreter.interpret(Interpreter.java:48)
at edu.rice.cs.drjava.model.repl.newjvm.InterpreterJVM.interpret(InterpreterJVM.java:251)
at edu.rice.cs.drjava.model.repl.newjvm.InterpreterJVM.interpret(InterpreterJVM.java:228)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:637)
Still present in r5211.
The conditional in ClassLoader.java that throws the exception is
if ((name != null) && name.startsWith("java.")) {
throw new SecurityException("Prohibited package name: " +
name.substring(0, name.lastIndexOf('.')));
}
We should print an error when switching into a java.* package.