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

Misleading error message when accessing a private static field

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.0-JSR-3
    • 1.0-JSR-4
    • None
    • None
    • Java 1.5.0_03 on Windows XP

    Description

      When accessing a private static field, you get a "NoSuchFieldException" instead of an "IllegalPropertyAccessException:"

      groovy> class A

      { static x }

      groovy> A.x = new Integer(10)
      groovy> go
      Caught: java.lang.NoSuchFieldException: x
      at CommandLine.run(CommandLine.groovy:2)

      With non-static fields, you get a more informative message:

      groovy> class A

      { def x }

      groovy> a = new A()
      groovy> a.x = new Integer(10)
      groovy> go
      Caught: groovy.lang.IllegalPropertyAccessException: Can not access the private field x in class A
      at gjdk.groovy.lang.MetaClass_GroovyReflector.invoke(Unknown Source)
      at A.setProperty(CommandLine.groovy)
      at CommandLine.run(CommandLine.groovy:1)

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            mcspanky Martin C. Martin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: