Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4.10
-
None
-
None
-
openjdk version "1.8.0_111"
OpenJDK Runtime Environment (build 1.8.0_111-8u111-b14-2~bpo8+1-b14)
OpenJDK 64-Bit Server VM (build 25.111-b14, mixed mode)
Description
It appears like a concurrent invocation of GroovyShell.evaluate results in a exception if the evaluated script contains an enum.
The following code reproduces this issue:
import groovy.lang.GroovyShell; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; public class MyReproducer { public static void main(String [] args) throws InterruptedException { // Uncomment this and the problem will go away //runScript(); ExecutorService es = Executors.newFixedThreadPool(2); es.execute(MyReproducer::runScript); es.execute(MyReproducer::runScript); es.shutdown(); es.awaitTermination(10, TimeUnit.SECONDS); } private static void runScript() { GroovyShell shell = new GroovyShell(); shell.evaluate("enum MyEnum {FOO, BAR, BAZ}\nprintln MyEnum.values()"); } }
Exception thrown:
Exception in thread "pool-1-thread-1" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: -1: unable to resolve class java$lang$Enum @ line -1, column -1. 1 error at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310) at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:958) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:605) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:554) at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688) at groovy.lang.GroovyShell.parse(GroovyShell.java:700) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:584) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594) at MyReproducer.runScript(MyReproducer.java:23) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Exception in thread "pool-1-thread-2" java.lang.ExceptionInInitializerError at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at org.codehaus.groovy.runtime.callsite.CallSiteArray$1.run(CallSiteArray.java:68) at org.codehaus.groovy.runtime.callsite.CallSiteArray$1.run(CallSiteArray.java:65) at java.security.AccessController.doPrivileged(Native Method) at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallStaticSite(CallSiteArray.java:65) at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:162) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) at Script1.run(Script1.groovy:2) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594) at MyReproducer.runScript(MyReproducer.java:23) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.TypeNotPresentException: Type java$lang$Enum not present at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117) at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125) at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49) at sun.reflect.generics.repository.ClassRepository.getSuperclass(ClassRepository.java:90) at java.lang.Class.getGenericSuperclass(Class.java:777) at com.sun.beans.TypeResolver.prepare(TypeResolver.java:308) at com.sun.beans.TypeResolver.resolve(TypeResolver.java:185) at com.sun.beans.TypeResolver.resolve(TypeResolver.java:218) at com.sun.beans.TypeResolver.resolve(TypeResolver.java:169) at com.sun.beans.TypeResolver.resolveInClass(TypeResolver.java:81) at java.beans.FeatureDescriptor.getReturnType(FeatureDescriptor.java:370) at java.beans.PropertyDescriptor.findPropertyType(PropertyDescriptor.java:648) at java.beans.PropertyDescriptor.updateGenericsFor(PropertyDescriptor.java:623) at java.beans.Introspector.addPropertyDescriptor(Introspector.java:605) at java.beans.Introspector.addPropertyDescriptors(Introspector.java:614) at java.beans.Introspector.getTargetPropertyInfo(Introspector.java:467) at java.beans.Introspector.getBeanInfo(Introspector.java:428) at java.beans.Introspector.getBeanInfo(Introspector.java:173) at groovy.lang.MetaClassImpl$15.run(MetaClassImpl.java:3318) at java.security.AccessController.doPrivileged(Native Method) at groovy.lang.MetaClassImpl.addProperties(MetaClassImpl.java:3316) at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:3293) at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:260) at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:302) at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:261) at org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:883) at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallStaticSite(CallSiteArray.java:75) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:214) at MyEnum.<clinit>(Script1.groovy) ... 18 more Caused by: java.lang.ClassNotFoundException: java$lang$Enum at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:677) at groovy.lang.GroovyClassLoader$InnerLoader.loadClass(GroovyClassLoader.java:425) at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:787) at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:775) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114) ... 48 more
The problem doesn't occur if a script containing an enum declaration was evaluated before. Also every once in a while everything works fine and no error occurs.
Please note: I was unable to reproduce this problem with 2.5.0-alpha-1 but since I didn't find a mention of this bug in the changelog I figured that I should report it nevertheless.
Attachments
Issue Links
- is duplicated by
-
GROOVY-8217 java.lang.ClassNotFoundException: java$lang$Enum
- Closed