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

@Immutable class, failure when trying to define private static members

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.4
    • 1.7.5, 1.8-beta-2
    • None
    • None
    • Mac OSX 10.6.3, JVM 1.6.0_20, Groovy 1.7.4

    Description

      Attempt to add 'private static' field to a class that has been
      annotated as @Immutable causes an error.

      Groovy Shell (1.7.4, JVM: 1.6.0_20)
      Type 'help' or '\h' for help.
      ------------------------------------------------------------------------------------------------------------------
      groovy:000> @Immutable class AClass

      { groovy:001> static final String FOO = 'bar' groovy:002> }

      ===> true
      groovy:000> @Immutable class BClass

      { groovy:001> private static final String FOO = 'bar' groovy:002> }

      ERROR org.codehaus.groovy.control.MultipleCompilationErrorsException:
      startup failed:
      groovysh_evaluate: -1: cannot modify static final field 'FOO' outside
      of static initialization block.
      @ line -1, column -1.
      groovysh_evaluate: -1: cannot modify static final field 'FOO' outside
      of static initialization block.
      @ line -1, column -1.
      2 errors
      ...

      In Groovy 1.7.3 it does not cause an error.
      Groovy Shell (1.7.3, JVM: 1.6.0_20)
      Type 'help' or '\h' for help.
      ------------------------------------------------------------------------------------------------------------------
      groovy:000> @Immutable class AClass

      { groovy:001> static final String FOO = 'bar' groovy:002> }

      ===> true
      groovy:000> @Immutable class BClass

      { groovy:001> private static final String FOO = 'bar' groovy:002> }

      ===> true
      groovy:000>
      ...

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              jlamsa Jarno Lamsa
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: