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

Misleading error message when accessing a private static field

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

          mcspanky Martin C. Martin created issue -
          phkim Kim, Pilho made changes -
          Field Original Value New Value
          Comment [ a.@x = new Integer(10) // This ia a workaround.
          ]
          phkim Kim, Pilho added a comment -

          a.@x = new Integer(10) // This ia a workaround since jsr-04

          X---------------------------------------------------------
          Lets get Groovy!
          ================
          Version: 1.0-jsr-04-SNAPSHOT JVM: 1.4.2_08-b03
          Type 'exit' to terminate the shell
          Type 'help' for command help
          Type 'go' to execute the statements

          groovy> class A

          { static x }

          groovy> A.@x = new Integer(10)
          groovy> go

          groovy> class A

          { def x }

          groovy> a = new A()
          groovy> a.@x = new Integer(10)
          groovy> go

          X---------------------------------------------------------

          phkim Kim, Pilho added a comment - a.@x = new Integer(10) // This ia a workaround since jsr-04 X--------------------------------------------------------- Lets get Groovy! ================ Version: 1.0-jsr-04-SNAPSHOT JVM: 1.4.2_08-b03 Type 'exit' to terminate the shell Type 'help' for command help Type 'go' to execute the statements groovy> class A { static x } groovy> A.@x = new Integer(10) groovy> go groovy> class A { def x } groovy> a = new A() groovy> a.@x = new Integer(10) groovy> go X---------------------------------------------------------
          blackdrag Jochen Theodorou added a comment - this should fix the issue http://cvs.codehaus.org/changelog/groovy/groovy/groovy-core/src/main?cs=MAIN:blackdrag:20050913202256
          blackdrag Jochen Theodorou made changes -
          Fix Version/s 1.0-JSR-4 [ 11905 ]
          Assignee Jochen Theodorou [ blackdrag ]
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Closed [ 6 ]
          markt Mark Thomas made changes -
          Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
          markt Mark Thomas made changes -
          Workflow jira [ 12730184 ] Default workflow, editable Closed status [ 12742172 ]
          markt Mark Thomas made changes -
          Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
          markt Mark Thomas made changes -
          Workflow jira [ 12972002 ] Default workflow, editable Closed status [ 12979768 ]

          People

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

            Dates

              Created:
              Updated:
              Resolved: