Issue Details (XML | Word | Printable)

Key: GROOVY-1882
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Blocker Blocker
Assignee: Jochen Theodorou
Reporter: agilewang
Votes: 3
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
groovy

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

Created: 09/May/07 09:27 PM   Updated: 05/Jul/07 05:08 AM
Component/s: groovy-jdk
Affects Version/s: 1.1-beta-1
Fix Version/s: 1.1-beta-2

Time Tracking:
Not Specified

File Attachments: 1. Text File GroovyScriptEngine.patch (2 kB)
2. Zip Archive test.zip (1 kB)

Environment: Windows XP SP2 / Sun JDK1.5..0_09

Testcase included: yes


 Description  « Hide
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?



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
agilewang added a comment - 10/May/07 10:55 AM
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.

Jochen Theodorou added a comment - 17/May/07 12:13 PM
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.

agilewang added a comment - 18/May/07 11:59 AM
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.


Jochen Theodorou added a comment - 05/Jul/07 05:08 AM
patched