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

MissingPropertyException thrown when referencing an externally declared constant from a switch case in an enum instance method

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.5
    • Fix Version/s: 2.1.3, 2.2.0-beta-1
    • Component/s: None
    • Labels:
      None
    • Environment:
      Mac OS X 10.7.5, IntelliJ IDEA 11.1.3

      Description

      For illustration see the code below:

      import javax.xml.stream.XMLStreamConstants
      
      enum MyEnum {
           INSTANCE {
              String getName(int i) {
                  switch (i) {
                      case javax.xml.stream.XMLStreamConstants.START_ELEMENT:
                          return "START_ELEMENT"
                      case XMLStreamConstants.END_ELEMENT:
                          return "END_ELEMENT"
                  }
              }
          }
      }
      
      println MyEnum.INSTANCE.getName(XMLStreamConstants.START_ELEMENT)
      println MyEnum.INSTANCE.getName(XMLStreamConstants.END_ELEMENT)
      

      The first invokation of getName succeeds because the constant is referenced with its fully qualified name in the first case statement. The second however fails in spite of the fact that the referenced class is imported.

      Exact output of the script is:

      START_ELEMENT
      Caught: groovy.lang.MissingPropertyException: No such property: XMLStreamConstants for class: MyEnum$1
      groovy.lang.MissingPropertyException: No such property: XMLStreamConstants for class: MyEnum$1
      	at MyEnum$1.getName(EnumMemberMethodWithSwitchTest.groovy:9)
      	at MyEnum$1$getName.call(Unknown Source)
      	at EnumMemberMethodWithSwitchTest.run(EnumMemberMethodWithSwitchTest.groovy:18)
      	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
      

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              zagyvaibalazs Balazs Zagyvai
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: