groovy

NullPointerException when running two or more scripts with GroovyScriptEngine in multiple threads .

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Blocker Blocker
  • Resolution: Fixed
  • Affects Version/s: 1.1-beta-1
  • Fix Version/s: 1.1-beta-2
  • Component/s: groovy-jdk
  • Labels:
    None
  • Environment:
    Windows XP SP2 / Sun JDK1.5..0_09
  • Testcase included:
    yes
  • Number of attachments :
    2

Description

NullPointerException is always thrown when running the two scripts in multiple threads with the same GroovyScriptEngine instance.

Besides the NPE,the result is not correct sometime.

Here is a wrong result:
java.lang.NullPointerException
at groovy.util.GroovyScriptEngine$ScriptCacheEntry.access$502(GroovyScriptEngine.java:101)
at groovy.util.GroovyScriptEngine.updateCacheEntry(GroovyScriptEngine.java:358)
at groovy.util.GroovyScriptEngine.run(GroovyScriptEngine.java:395)
at GroovyConcurrentTest$ScriptRunner.run(GroovyConcurrentTest.java:63)
run :script2.groovy result:script2
run :script3.groovy result:null
run :script2.groovy result:script2
run :script2.groovy result:script2
run :script2.groovy result:script2
run :script2.groovy result:script2
run :script2.groovy result:script2
run :script2.groovy result:script2
run :script2.groovy result:script2
run :script2.groovy result:script2
run :script2.groovy result:script2
run :script2.groovy result:script2
run :script2.groovy result:script2
run :script2.groovy result:script2
run :script3.groovy result:script2
run :script3.groovy result:script2
run :script3.groovy result:script2
run :script3.groovy result:script2
run :script3.groovy result:script2
run :script3.groovy result:script2
run :script2.groovy result:script2
run :script2.groovy result:script2
run :script2.groovy result:script2
run :script2.groovy result:script2
run :script2.groovy result:script2
run :script2.groovy result:script2
run :script3.groovy result:script2
run :script3.groovy result:script2
run :script3.groovy result:script2
run :script3.groovy result:script2
run :script3.groovy result:script2
run :script3.groovy result:script2
run :script3.groovy result:script2
run :script3.groovy result:script2
run :script3.groovy result:script2
run :script3.groovy result:script2
run :script3.groovy result:script2
run :script3.groovy result:script2
run :script3.groovy result:script2

I extpect the resut looks like this:
run :script2.groovy result:script2
run :script3.groovy result:script3

Maybe the NPE is caused by the currentCacheEntry is null?

Activity

Hide
agilewang added a comment -

I was trying to fix this bug, and created a patch file. You can apply it to see whether it 's right to help repair bug.
Thanks.

Show
agilewang added a comment - I was trying to fix this bug, and created a patch file. You can apply it to see whether it 's right to help repair bug. Thanks.
Hide
blackdrag blackdrag added a comment -

hmm... currentCacheEntry could be null while findClass is executed. That would explain the NPE. The synchronization on an interned String gives me a little headache... but should work. But there is no guaranteee, that findClass would be executed only from the GroovyScriptEngine... Additionally I have doubts, that the dependency tracking will work this way in all cases. findClass is not always executed. IMHO the usage of ResourceConnector should be reaplced with GroovyResourceLoader and GroovyClassLoader should be used more directly.

Show
blackdrag blackdrag added a comment - hmm... currentCacheEntry could be null while findClass is executed. That would explain the NPE. The synchronization on an interned String gives me a little headache... but should work. But there is no guaranteee, that findClass would be executed only from the GroovyScriptEngine... Additionally I have doubts, that the dependency tracking will work this way in all cases. findClass is not always executed. IMHO the usage of ResourceConnector should be reaplced with GroovyResourceLoader and GroovyClassLoader should be used more directly.
Hide
agilewang added a comment -

As you said that the use of currentCacheEntry is not precise.

Besides the above problem if someone call loadScriptByName to get a scipt class,the current class implement is not thread safe,and so on.
It's implements thrown CurrentModifyExcepiton in Groovy1.0,but to 1.1-beta-1,is not thread safe also.

So I suggest it's a good idea that the current implements should be reimplemented.

BTW,does the GRails use this class?I haven't used it.
Thanks.

Show
agilewang added a comment - As you said that the use of currentCacheEntry is not precise. Besides the above problem if someone call loadScriptByName to get a scipt class,the current class implement is not thread safe,and so on. It's implements thrown CurrentModifyExcepiton in Groovy1.0,but to 1.1-beta-1,is not thread safe also. So I suggest it's a good idea that the current implements should be reimplemented. BTW,does the GRails use this class?I haven't used it. Thanks.
Hide
blackdrag blackdrag added a comment -

patched

Show
blackdrag blackdrag added a comment - patched

People

Vote (3)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: