groovy
  1. groovy
  2. GROOVY-3911

intended behaviour change in 1.7rc1? can no longer set final variable in static initializer

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.7-rc-1
    • Fix Version/s: 1.7-rc-2
    • Component/s: Compiler
    • Labels:
      None
    • Number of attachments :
      0

      Description

      I'm just checking if this is intended .... as it seems a difference from 1.7beta2 and also a difference from pure java.

      This compiles under javac:

      class A {
      
        static final String foo;
      
        static {
          if (true) {
            foo = "roshan";
          } else {
            foo = "jochen";
          }
        }
      }
      

      and it compiles under 1.7beta2, but under 1.7rc1 I get:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      A.groovy: 7: cannnot access final field or property outside of constructor.
       @ line 7, column 7.
               foo = "roshan";
               ^
      
      A.groovy: 9: cannnot access final field or property outside of constructor.
       @ line 9, column 7.
               foo = "jochen";
               ^
      
      2 errors
      

        Activity

        Hide
        Roshan Dawrani added a comment -

        I think it is a bug - when the final variable is static, it should be allowed to be set in static constructor - same as instance level final variables are allowed to be set in non-static constructors.

        Show
        Roshan Dawrani added a comment - I think it is a bug - when the final variable is static, it should be allowed to be set in static constructor - same as instance level final variables are allowed to be set in non-static constructors.
        Hide
        blackdrag blackdrag added a comment -

        arg, no, that was not intended... the exclusion filter is not handling static consructors it seems.

        Show
        blackdrag blackdrag added a comment - arg, no, that was not intended... the exclusion filter is not handling static consructors it seems.
        Hide
        Roshan Dawrani added a comment -

        Fixed.

        Show
        Roshan Dawrani added a comment - Fixed.

          People

          • Assignee:
            Roshan Dawrani
            Reporter:
            Andy Clement
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: