Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4099

@Immutable annotation does not allow untyped static fields

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.0
    • 1.7.2, 1.8-beta-1
    • None
    • None

    Description

      I cannot compile a class with @Immutable if it has a static field declared with def. I don't think the transform should touch static fields.

      ~$ cat ImmutableTest.groovy
      @Immutable                                 
      class ImmutableTest {                      
        static foo = {}                          
      }                                          
      marcus@better:~$ groovyc ImmutableTest.groovy 
      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      General error during canonicalization: @Immutable processor doesn't know how to handle field 'foo' of type 'java.lang.Object or def' while compiling class ImmutableTest.                                                                         
      @Immutable classes currently only support properties with known immutable types or types where special handling achieves immutable behavior, including:                                                                                           
      - Strings, primitive types, wrapper types, BigInteger and BigDecimal                                                     
      - enums, other @Immutable classes and known immutables (java.awt.Color)                                                  
      - Cloneable classes, collections, maps and arrays, and other classes with special handling (java.util.Date)              
      Other restrictions apply, please see the groovydoc for @Immutable for further details                                    
      
      java.lang.RuntimeException: @Immutable processor doesn't know how to handle field 'foo' of type 'java.lang.Object or def' while compiling class ImmutableTest.                                                                                    
      @Immutable classes currently only support properties with known immutable types or types where special handling achieves immutable behavior, including:                                                                                           
      - Strings, primitive types, wrapper types, BigInteger and BigDecimal
      - enums, other @Immutable classes and known immutables (java.awt.Color)
      - Cloneable classes, collections, maps and arrays, and other classes with special handling (java.util.Date)
      Other restrictions apply, please see the groovydoc for @Immutable for further details
              at org.codehaus.groovy.transform.ImmutableASTTransformation.createConstructorStatement(ImmutableASTTransformation.java:373)
              at org.codehaus.groovy.transform.ImmutableASTTransformation.createConstructorMap(ImmutableASTTransformation.java:324)
              at org.codehaus.groovy.transform.ImmutableASTTransformation.createConstructor(ImmutableASTTransformation.java:310)
              at org.codehaus.groovy.transform.ImmutableASTTransformation.visit(ImmutableASTTransformation.java:113)
              at org.codehaus.groovy.transform.ASTTransformationVisitor.visitClass(ASTTransformationVisitor.java:129)
              at org.codehaus.groovy.transform.ASTTransformationVisitor$2.call(ASTTransformationVisitor.java:173)
              at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:957)
              at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:517)
              at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:495)
              at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:472)
              at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:456)
              at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:57)
              at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:170)
              at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompile(FileSystemCompiler.java:138)
              at org.codehaus.groovy.tools.FileSystemCompiler.main(FileSystemCompiler.java:152)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:616)
              at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108)
              at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130)
      
      1 error
      

      Attachments

        1. ImmutableTest.groovy
          0.1 kB
          Marcus Better

        Activity

          People

            paulk Paul King
            marcusb Marcus Better
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: