Groovy
  1. Groovy
  2. GROOVY-5335

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

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Cannot Reproduce
    • 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

      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).

      1. bug.zip
        2 kB
        Troy Nichols

        Issue Links

          Activity

          Troy Nichols created issue -
          Troy Nichols made changes -
          Field Original Value New Value
          Attachment bug.zip [ 59020 ]
          Cédric Champeau made changes -
          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:

          <pre>
          public interface IA {
            public static final String NAME = "IA";
          }

          public interface IB extends IA {
            public static final String NAME = "IB";
          }
          </pre>

          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:

          <pre>
          public class A {
            public static final String NAME = "A";
          }

          public class B extends A {
            public static final String NAME = "B";
          }
          </pre>

          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).
          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:

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

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

          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:

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

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

          {{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).
          Cédric Champeau made changes -
          Link This issue relates to GROOVY-5272 [ GROOVY-5272 ]
          Jochen Theodorou made changes -
          Component/s Compiler [ 13529 ]
          Mark Thomas made changes -
          Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
          Mark Thomas made changes -
          Workflow jira [ 12734258 ] Default workflow, editable Closed status [ 12746054 ]
          Mark Thomas made changes -
          Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
          Mark Thomas made changes -
          Workflow jira [ 12973765 ] Default workflow, editable Closed status [ 12980919 ]
          Pascal Schumacher made changes -
          Status Open [ 1 ] Closed [ 6 ]
          Resolution Cannot Reproduce [ 5 ]

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development