为什么groovyc与安全经理发生冲突?

时间:2016-04-23 15:03:02

标签: groovy centos7

我的平台是CentOS 7 groovy 1.8.9-7,这可能是相关的。

$ groovy -version
Groovy Version: 1.8.9 JVM: 1.7.0_99 Vendor: Oracle Corporation OS: Linux
$ java -version
java version "1.7.0_99"
OpenJDK Runtime Environment (rhel-2.6.5.0.el7_2-x86_64 u99-b00)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)

我有一个简单的groovy文件:

#!/usr/bin/env groovy
println System.getProperty("java.class.path")

如果我运行它,它可以正常工作,例如:

$ groovy info.groovy 
/usr/share/java/ant.jar:/usr/share/java/ant/ant-junit.jar:/usr/share/java/ant-launcher.jar:/usr/share/java/antlr.jar:/usr/share/java/objectweb-asm/asm.jar:/usr/share/java/objectweb-asm/asm-analysis.jar:/usr/shar
e/java/objectweb-asm/asm-tree.jar:/usr/share/java/objectweb-asm/asm-util.jar:/usr/share/java/bsf.jar:/usr/share/java/commons-cli.jar:/usr/share/java/commons-logging.jar:/usr/share/java/groovy.jar:/usr/share/java
/ivy.jar:/usr/share/java/jline.jar:/usr/share/java/jsp.jar:/usr/share/java/junit.jar:/usr/share/java/servlet.jar:/usr/share/java/xstream.jar:/usr/share/java/jansi.jar

然而,groovyc对它嗤之以鼻:

$ groovyc info.groovy                                                                                                                                                         [19/472]
>>> a serious error occurred: BUG! exception in phase 'semantic analysis' in source unit 'info.groovy' Prohibited package name: java.lang
>>> stacktrace:
BUG! exception in phase 'semantic analysis' in source unit 'info.groovy' Prohibited package name: java.lang
        at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:850)
        at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:550)
        at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:499)
        at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:482)
        at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:60)
        at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:216)
        at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompile(FileSystemCompiler.java:149)
        at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompileWithErrorHandling(FileSystemCompiler.java:179)
        at org.codehaus.groovy.tools.FileSystemCompiler.main(FileSystemCompiler.java:163)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108)
        at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130)
Caused by: java.lang.SecurityException: Prohibited package name: java.lang
        at java.lang.ClassLoader.preDefineClass(ClassLoader.java:661)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:797)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at org.codehaus.groovy.tools.RootLoader.oldFindClass(RootLoader.java:152)
        at org.codehaus.groovy.tools.RootLoader.loadClass(RootLoader.java:124)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:412)
        at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:692)
        at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:560)
        at org.codehaus.groovy.control.ClassNodeResolver.tryAsLoaderClassOrScript(ClassNodeResolver.java:183)
[...]

为什么以及如何解决?

1 个答案:

答案 0 :(得分:0)

我没有弄清楚确切的问题,但它似乎对我的开发环境来说是独一无二的。在新安装的CentOS 7或RHEL 7中安装groovy似乎工作正常。