groovy
  1. groovy
  2. GROOVY-5335

Constants defined in sub-interfaces which hide super-interface constants evaluate unpredictably

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.8.6, 2.0-beta-3
    • Fix Version/s: None
    • Component/s: Compiler
    • Labels:
      None
    • Environment:
      OS:
       Mac OSX 10.6.8

      Groovy versions tested:
       Groovy Version: 2.0.0-beta-3-SNAPSHOT JVM: 1.6.0_29
       Groovy Version: 1.8.6 JVM: 1.6.0_29
       Groovy Version: 1.7.10 JVM: 1.6.0_29
    • Testcase included:
      yes
    • Number of attachments :
      1

      Description

      It seems Groovy does not have a predictable behavior for reading static fields
      on sub-interfaces which "hide" a field from their super-interface.

      Example:

      public interface IA {
        public static final String NAME = "IA";
      }
      
      public interface IB extends IA {
        public static final String NAME = "IB";
      }
      

      You would expect, based on Java's behavior, that IB.NAME should always equal "IB",
      but groovy sometimes gives "IB" and sometimes "IA."

      This seems to happen whether the interface is defined in Java or groovy, and whether or
      not the field is static/final.

      However, it does seem to only happen with interfaces, not with classes.
      i.e. the following works as expected:

      public class A {
        public static final String NAME = "A";
      }
      
      public class B extends A {
        public static final String NAME = "B";
      }
      

      B.NAME will always give "B" in that case.

      See attached test case in bug.zip (unzip bug.zip, cd into 'bug' directory, run test_java.sh and test_groovy.sh)
      test_java.sh shows the behavior you get from Java, which is the behavior I would expect, and test_groovy.sh shows the actual behavior (sometimes prints "A", sometimes prints "B"). I can't find any pattern to the wrong behavior. Seems like it's just luck of the draw as to which field gets read (sub-interface or super-interface).

        Issue Links

          Activity

          Hide
          CÚdric Champeau added a comment -

          Formatting tags

          Show
          CÚdric Champeau added a comment - Formatting tags
          Hide
          CÚdric Champeau added a comment -

          I am puzzled, seems the very same issue as GROOVY-5272, but it is supposed to be fixed. I cannot reproduce on master here. Maybe it's related to the Mac OS X JVM?

          Show
          CÚdric Champeau added a comment - I am puzzled, seems the very same issue as GROOVY-5272 , but it is supposed to be fixed. I cannot reproduce on master here. Maybe it's related to the Mac OS X JVM?
          Hide
          Paul King added a comment -

          I can reproduce on Groovy 1.8.5 but can't reproduce on Windows for Groovy 1.8.6.

          Show
          Paul King added a comment - I can reproduce on Groovy 1.8.5 but can't reproduce on Windows for Groovy 1.8.6.
          Hide
          CÚdric Champeau added a comment -

          I cannot reproduce. Can you add:

          println GroovySystem.version
          

          at the beginning of your test script?

          Show
          CÚdric Champeau added a comment - I cannot reproduce. Can you add: println GroovySystem.version at the beginning of your test script?

            People

            • Assignee:
              Unassigned
              Reporter:
              Troy Nichols
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: