SecurityException when running a Groovy script within IDEA 10

I'm attempting to run a pretty simple Groovy script within IDEA 10 on a Mac. However, I'm getting the following error:

Caught: java.lang.SecurityException: Prohibited package name: java.text

From doing some searching, IDEA had similar problems running groovy scripts a couple of versions ago, but it was on the java.lang package.  The fixes for that problem don't seem to help the java.text problem.

The class I'm trying to access is SimpleDateFormat.

Has anybody run into this and been able to find a workaround (other than running it outside of IDEA of course).

Thanks!

7 comments
Comment actions Permalink

Could you please post the whole console output (with classpath) here?

0
Comment actions Permalink

/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:57691,suspend=y,server=n -Dtools.jar=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/tools.jar -Dgroovy.home=/Users/myuser/.m2/repository/org/codehaus/groovy/groovy-all/1.7.6 -Dgroovy.starter.conf=/Applications/IntelliJ IDEA 10.app/plugins/Groovy/lib/groovy-starter.conf -javaagent:/Users/myuser/Library/Caches/IntelliJIdea10/groovyHotSwap/gragent.jar -Dfile.encoding=MacRoman -classpath /Users/myuser/.m2/repository/org/codehaus/groovy/groovy-all/1.7.6/groovy-all-1.7.6.jar:/Applications/IntelliJ IDEA 10.app/lib/idea_rt.jar org.codehaus.groovy.tools.GroovyStarter --conf /Applications/IntelliJ IDEA 10.app/plugins/Groovy/lib/groovy-starter.conf --main groovy.ui.GroovyMain --classpath /Users/myuser/Projects/myproj/modules/core/target/classes:/Users/myuser/Applications/Java/Libraries/gwt2.1/gwt-user.jar:/Users/myuser/Projects/myproj/modules/util/target/classes:/Users/myuser/Projects/myproj/modules/shared/target/classes:/Users/myuser/Projects/myproj/modules/gwtutil/target/classes:/Users/myuser/.m2/repository/com/google/gwt/gwt-servlet/2.1.0/gwt-servlet-2.1.0.jar:/Users/myuser/.m2/repository/com/google/code/gwt-log/gwt-log/3.0/gwt-log-3.0.jar:/Users/myuser/.m2/repository/org/springframework/spring-core/3.0.3.RELEASE/spring-core-3.0.3.RELEASE.jar:/Users/myuser/.m2/repository/org/springframework/spring-asm/3.0.3.RELEASE/spring-asm-3.0.3.RELEASE.jar:/Users/myuser/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar:/Users/myuser/.m2/repository/org/springframework/spring-context/3.0.3.RELEASE/spring-context-3.0.3.RELEASE.jar:/Users/myuser/.m2/repository/org/springframework/spring-aop/3.0.3.RELEASE/spring-aop-3.0.3.RELEASE.jar:/Users/myuser/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar:/Users/myuser/.m2/repository/org/springframework/spring-beans/3.0.3.RELEASE/spring-beans-3.0.3.RELEASE.jar:/Users/myuser/.m2/repository/org/springframework/spring-expression/3.0.3.RELEASE/spring-expression-3.0.3.RELEASE.jar:/Users/myuser/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar:/Users/myuser/.m2/repository/commons-lang/commons-lang/2.4/commons-lang-2.4.jar:/Users/myuser/.m2/repository/commons-codec/commons-codec/1.3/commons-codec-1.3.jar:/Users/myuser/.m2/repository/commons-pool/commons-pool/1.4/commons-pool-1.4.jar:/Users/myuser/.m2/repository/commons-dbcp/commons-dbcp/1.2.2/commons-dbcp-1.2.2.jar:/Users/myuser/.m2/repository/commons-httpclient/commons-httpclient/3.1/commons-httpclient-3.1.jar:/Users/myuser/.m2/repository/net/sf/ehcache/ehcache-core/2.2.0/ehcache-core-2.2.0.jar:/Users/myuser/.m2/repository/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar:/Users/myuser/.m2/repository/net/sf/ehcache/ehcache-terracotta/2.2.0/ehcache-terracotta-2.2.0.jar:/Users/myuser/.m2/repository/org/terracotta/terracotta-toolkit-1.0-runtime/1.0.0/terracotta-toolkit-1.0-runtime-1.0.0.jar:/Users/myuser/.m2/repository/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar:/Users/myuser/.m2/repository/com/google/collections/google-collections/1.0/google-collections-1.0.jar:/Users/myuser/.m2/repository/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar:/Users/myuser/.m2/repository/mysql/mysql-connector-java/5.1.9/mysql-connector-java-5.1.9.jar:/Users/myuser/.m2/repository/com/thoughtworks/xstream/xstream/1.3/xstream-1.3.jar:/Users/myuser/.m2/repository/xpp3/xpp3_min/1.1.4c/xpp3_min-1.1.4c.jar:/Users/myuser/.m2/repository/org/mybatis/mybatis/3.0.2/mybatis-3.0.2.jar:/Users/myuser/.m2/repository/com/amazonaws/aws-java-sdk/1.1.4/aws-java-sdk-1.1.4.jar:/Users/myuser/.m2/repository/org/codehaus/jackson/jackson-core-asl/1.7.1/jackson-core-asl-1.7.1.jar:/Users/myuser/.m2/repository/javax/mail/mail/1.4/mail-1.4.jar:/Users/myuser/.m2/repository/javax/activation/activation/1.1/activation-1.1.jar:/Users/myuser/.m2/repository/stax/stax-api/1.0.1/stax-api-1.0.1.jar:/Users/myuser/.m2/repository/org/aspectj/aspectjrt/1.6.9/aspectjrt-1.6.9.jar:/Users/myuser/.m2/repository/org/springframework/spring-orm/3.0.3.RELEASE/spring-orm-3.0.3.RELEASE.jar:/Users/myuser/.m2/repository/org/springframework/spring-jdbc/3.0.3.RELEASE/spring-jdbc-3.0.3.RELEASE.jar:/Users/myuser/.m2/repository/org/springframework/spring-tx/3.0.3.RELEASE/spring-tx-3.0.3.RELEASE.jar:/Users/myuser/.m2/repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar:/Users/myuser/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar:/Users/myuser/.m2/repository/org/codehaus/groovy/groovy-all/1.7.6/groovy-all-1.7.6.jar /Users/myuser/Projects/myproj/modules/core/src/main/groovy/com/myproj/core/script/AWS.groovy
Connected to the target VM, address: '127.0.0.1:57691', transport: 'socket'
log4j:WARN No appenders could be found for logger (org.apache.commons.httpclient.params.DefaultHttpParams).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Caught: java.lang.ExceptionInInitializerError
at com.myproj.core.script.AWS.run(AWS.groovy:32)
Disconnected from the target VM, address: '127.0.0.1:57691', transport: 'socket'

Process finished with exit code 1

0
Comment actions Permalink

I don't see any SecurityException in this output. How did you find this was the cause? Could you post its own stacktrace here?

0
Comment actions Permalink

I have to modify my Java classes to get the actual exception in the stack trace:

Caught: java.lang.SecurityException: Prohibited package name: java.text
 at com.multipaas.core.script.AWS.run(AWS.groovy:32)


The error from the original stack trace is the same root cause, but it gets stopped in a static initializer.

Also, you can get a similar error if you just create a simple groovy script with the following line:

dateFormat = new java.text.SimpleDateFormat("MM/dd/yyyy");

It will create an error during semantic analysis even before executing.
0
Comment actions Permalink

I cannot reproduce this problem. It appears thet org.codehaus.groovy.tools.RootLoader#loadClass has to do with it. Could you please put a breakpoint there, run your script in the debug mode and stop when it tries to load java.text.SimpleDateFormat? At this point, it's interesting to see which URLs this classloader searches in.

0
Comment actions Permalink

Thank you for the pointer.  It helped me figure out the problem.

I'm using GWT, and I have my own java.text.SimpleDateFormat class in a gwtemul GWT module.  The path is actually com/denormans/gwtemul/java/text, but since the package of the class is set to java.text, IDEA compiles this file as classes/java/text/SimpleDateFormat.class, which the loader picks up.  It's in my maven resources directory, which is in my source (since it also contains properties files that IDEA needs to load).

I would like to keep it as part of the source path so I can edit as Java source, but I'm not sure how to tell IDEA to not compile it.

-- Michael

0
Comment actions Permalink

You could either excude from compiletion this particular file (in the compiler settings) or mark the whole source dir as non-source.

0

Please sign in to leave a comment.