Skip to content

Modification exception in ImmutableClassNode.enableWriteProtection(...) #132

@bradbeck

Description

@bradbeck

Environment

  • groovy 2.4.3
  • groovy-eclipse-compiler 2.9.2-01
  • groovy-eclipse-batch 2.4.3-01
  • takari-smart-builder 0.4.0
  • maven 3.3.3

Description

Running a parallel maven build with "mvn --builder smart -T1C clean install -DskipTests" occasionally causes the following error:

[ERROR] /*
[ERROR] ^
[ERROR] General error during class generation: java.lang.UnsupportedOperationException
[ERROR] 
[ERROR] java.lang.UnsupportedOperationException
[ERROR] at java.util.Collections$UnmodifiableMap.put(Collections.java:1457)
[ERROR] at org.codehaus.groovy.ast.ImmutableClassNode.enableWriteProtection(ImmutableClassNode.java:128)
[ERROR] at org.codehaus.groovy.ast.ImmutableClassNode.getDeclaredMethods(ImmutableClassNode.java:120)
[ERROR] at org.codehaus.groovy.ast.ClassNode.getMethods(ClassNode.java:1004)
[ERROR] at org.codehaus.groovy.classgen.ClassCompletionVerifier.checkMethodForWeakerAccessPrivileges(ClassCompletionVerifier.java:369)
[ERROR] at org.codehaus.groovy.classgen.ClassCompletionVerifier.checkMethodsForWeakerAccess(ClassCompletionVerifier.java:266)
[ERROR] at org.codehaus.groovy.classgen.ClassCompletionVerifier.visitClass(ClassCompletionVerifier.java:66)
[ERROR] at org.codehaus.groovy.control.CompilationUnit$6.call(CompilationUnit.java:857)
[ERROR] at org.codehaus.groovy.control.CompilationUnit$6.call(CompilationUnit.java:909)
[ERROR] at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1221)
[ERROR] at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:651)
[ERROR] at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:629)
[ERROR] at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:606)
[ERROR] at org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.processToPhase(GroovyCompilationUnitDeclaration.java:202)
[ERROR] at org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.generateCode(GroovyCompilationUnitDeclaration.java:1711)
[ERROR] at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:838)
[ERROR] at org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:137)
[ERROR] at java.lang.Thread.run(Thread.java:745)

ImmutableClassNode.java:128

It appears that at least two threads think that writeProtected == false and both try to enter the synchronized enableWriteProtection() method. One will block
while the other is creating the unmodifiableMap. But when the blocked thread then executes the enableWriteProtection() method it will generate the above error.

One solution is to make writeProtected volatile and check it again inside the enableWriteProtection() method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions