Janino

ConcurrentModificationException due to instance variable of Class type initialized using a class literal

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    janino 2.5.9, jdk 5
  • Testcase included:
    yes
  • Number of attachments :
    0

Description

The following statement :
new SimpleCompiler().cook(new StringReader("class Test{Class c = String.class;}"));

throws Exception in thread "main" java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:449)
at java.util.AbstractList$Itr.next(AbstractList.java:420)
at org.codehaus.janino.UnitCompiler.initializeInstanceVariablesAndInvokeInstanceInitializers(UnitCompiler.java:4220)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1523)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:231)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:112)
at org.codehaus.janino.UnitCompiler$1.visitPackageMemberClassDeclaration(UnitCompiler.java:85)
at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:676)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:91)
at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:69)
at org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java:396)
at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:224)
at org.codehaus.janino.Cookable.cook(Cookable.java:68)
at org.codehaus.janino.Cookable.cook(Cookable.java:60)

Static variables don't throw any exceptions though.

Activity

Hide
Arno Unkrig added a comment -

Hi Varghese,

I can't fix this right now because I'm not at home, but if you change the first two lines of UnitCompiler.initializeInstanceVariablesAndInvokeInstanceInitializers() from

for (Iterator it = cd.getDeclaringClass().variableDeclaratorsAndInitializers.iterator(); it.hasNext();) {
    Java.TypeBodyDeclaration tbd = (Java.TypeBodyDeclaration) it.next();

to

for (int i = 0; i < cd.getDeclaringClass().variableDeclaratorsAndInitializers.size(); ++i) {
    Java.TypeBodyDeclaration tbd = (Java.TypeBodyDeclaration) cd.getDeclaringClass().variableDeclaratorsAndInitializers.get(i);

, then it should work fine... please complain if not!

CU

Arno

Show
Arno Unkrig added a comment - Hi Varghese, I can't fix this right now because I'm not at home, but if you change the first two lines of UnitCompiler.initializeInstanceVariablesAndInvokeInstanceInitializers() from
for (Iterator it = cd.getDeclaringClass().variableDeclaratorsAndInitializers.iterator(); it.hasNext();) {
    Java.TypeBodyDeclaration tbd = (Java.TypeBodyDeclaration) it.next();
to
for (int i = 0; i < cd.getDeclaringClass().variableDeclaratorsAndInitializers.size(); ++i) {
    Java.TypeBodyDeclaration tbd = (Java.TypeBodyDeclaration) cd.getDeclaringClass().variableDeclaratorsAndInitializers.get(i);
, then it should work fine... please complain if not! CU Arno
Hide
Varghese C V added a comment -

Hi Arno,

It works fine after applying the changes.

Thanks
Varghese C V

Show
Varghese C V added a comment - Hi Arno, It works fine after applying the changes. Thanks Varghese C V
Hide
Arno Unkrig added a comment -

Yep, the fix will go into 2.5.10 (no release date scheduled yet).

Show
Arno Unkrig added a comment - Yep, the fix will go into 2.5.10 (no release date scheduled yet).

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: