Groovy
  1. Groovy
  2. GROOVY-4964

static import overrides explicit class name when getting property

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.7.8, 1.8.1
    • Fix Version/s: 1.8.2, 1.9-beta-3
    • Component/s: None
    • Labels:
      None

      Description

      When I static import a method, it takes precedence over a call to the method explicitly on another class, if I get a property from the result.

      $ cat Foo.groovy 
      class Foo {
          static doIt() { [k: 'foo'] }
      }
      
      jbeutel@jbeutel-mac:~/proj/groovySandboxes/staticImports (master *)
      $ cat Bar.groovy 
      import static Foo.*
      class Bar {
          static doIt() { [k: 'bar'] }
          static doAssert() {
              assert doIt().k == 'foo'
              assert doIt() == [k: 'foo']
              assert Bar.doIt() == [k: 'bar']
              assert Bar.doIt().k == 'bar'
          }
      }
      
      jbeutel@jbeutel-mac:~/proj/groovySandboxes/staticImports (master *)
      $ groovy -e 'Bar.doAssert()'
      Caught: Assertion failed: 
      
      assert Bar.doIt().k == 'bar'
                        | |
                        | false
                        foo
      
      Assertion failed: 
      
      assert Bar.doIt().k == 'bar'
                        | |
                        | false
                        foo
      
      	at Bar.doAssert(Bar.groovy:8)
      	at Bar$doAssert.call(Unknown Source)
      	at script_from_command_line.run(script_from_command_line:1)
      
      jbeutel@jbeutel-mac:~/proj/groovySandboxes/staticImports (master *)
      $ groovy --version
      Groovy Version: 1.8.1 JVM: 1.6.0_26
      

      This was a problem for me when statically importing (with wildcards) a bunch of enum classes into another enum.

      Work-around: assign the method result to a temporary variable before getting a property from it.

        Activity

        J. David Beutel created issue -
        Jochen Theodorou made changes -
        Field Original Value New Value
        Assignee Paul King [ paulk ]
        Hide
        J. David Beutel added a comment -

        For the method calls without an explicit class, I'm not sure if the statically imported method should take precedence over the local method. But either way, I expect the last assert to succeed.

        Show
        J. David Beutel added a comment - For the method calls without an explicit class, I'm not sure if the statically imported method should take precedence over the local method. But either way, I expect the last assert to succeed.
        Hide
        Paul King added a comment -

        Should be fixed - thanks for finding the issue.

        We are still getting our CI servers switched over to git, so if you want to test in the very short term, you will need to build yourself from source. Once we have completed the switch, a snapshot jar should be available in the codehaus snapshot repo.

        Show
        Paul King added a comment - Should be fixed - thanks for finding the issue. We are still getting our CI servers switched over to git, so if you want to test in the very short term, you will need to build yourself from source. Once we have completed the switch, a snapshot jar should be available in the codehaus snapshot repo.
        Paul King made changes -
        Resolution Fixed [ 1 ]
        Fix Version/s 1.9-beta-2 [ 17494 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 1.8.2 [ 17495 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12733890 ] Default workflow, editable Closed status [ 12745712 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12971442 ] Default workflow, editable Closed status [ 12979262 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        24d 6h 30m 1 Paul King 29/Aug/11 07:40
        Resolved Resolved Closed Closed
        9d 7h 33m 1 Paul King 07/Sep/11 15:13

          People

          • Assignee:
            Paul King
            Reporter:
            J. David Beutel
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development