Groovy
  1. Groovy
  2. GROOVY-5335

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

    Details

    • Type: Bug Bug
    • Status: 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

      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

          No work has yet been logged on this issue.

            People

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

              Dates

              • Created:
                Updated:

                Development