groovy
  1. groovy
  2. GROOVY-5272

Intermittant/random incorrect resolution of sub-interface constant values

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.5
    • Fix Version/s: 1.8.6, 2.0-beta-3
    • Component/s: groovy-jdk
    • Labels:
      None
    • Environment:
      Windows XP and LINUX
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      If a constant in a sub-interface replaces/shadows a constant in a super interface (both Java), when trying to access the sub-interface's constant value from Groovy, the behaviour is intermittantly incorrect - sometimes the sub-interface's value is returned (correct) and sometimes the super interface's value is returned (incorrect).
      In Java the sub-interface's value is always returned, as expected.

      See source code below that demonstrates this: InterfaceA.java, InterfaceB.java, ShowBugGroovy.groovy, ShowBugJava.java
      If ShowBugGroovy is repeatedly run, sometimes the assertion fails, sometimes it passes (randomly?). I believe the behaviour is the same for concrete implementations of the sub-interface.

      package groovybug;
      
      public interface InterfaceA {
          String FOO="Foo A";
      }
      
      package groovybug;
      
      public interface InterfaceB extends InterfaceA {
          String FOO="Foo B";
      }
      
      package groovybug
      
      class ShowBugGroovy {
          static main(args) {
              println("Interface A: " + InterfaceA.FOO);
              println("Interface B: " + InterfaceB.FOO);
      
              // Fails randomly
              assert(InterfaceA.FOO!=InterfaceB.FOO)
          }
      }
      
      package groovybug;
      
      public class ShowBugJava {
          public static void main(String[] args) {
              System.out.println("Interface A: " + InterfaceA.FOO);
              System.out.println("Interface B: " + InterfaceB.FOO);
      
              // Always passes
              assert(!InterfaceA.FOO.equals(InterfaceB.FOO));
          }
      }
      

        Issue Links

          Activity

          Guillaume Laforge made changes -
          Field Original Value New Value
          Description If a constant in a sub-interface replaces/shadows a constant in a super interface (both Java), when trying to access the sub-interface's constant value from Groovy, the behaviour is intermittantly incorrect - sometimes the sub-interface's value is returned (correct) and sometimes the super interface's value is returned (incorrect).
          In Java the sub-interface's value is always returned, as expected.

          See source code below that demonstrates this: InterfaceA.java, InterfaceB.java, ShowBugGroovy.groovy, ShowBugJava.java
          If ShowBugGroovy is repeatedly run, sometimes the assertion fails, sometimes it passes (randomly?). I believe the behaviour is the same for concrete implementations of the sub-interface.


          package groovybug;

          public interface InterfaceA {
              String FOO="Foo A";
          }

          -

          package groovybug;

          public interface InterfaceB extends InterfaceA {
              String FOO="Foo B";
          }

          -

          package groovybug

          class ShowBugGroovy {
              static main(args) {
                  println("Interface A: " + InterfaceA.FOO);
                  println("Interface B: " + InterfaceB.FOO);

                  // Fails randomly
                  assert(InterfaceA.FOO!=InterfaceB.FOO)
              }
          }

          -

          package groovybug;

          public class ShowBugJava {
              public static void main(String[] args) {
                  System.out.println("Interface A: " + InterfaceA.FOO);
                  System.out.println("Interface B: " + InterfaceB.FOO);

                  // Always passes
                  assert(!InterfaceA.FOO.equals(InterfaceB.FOO));
              }
          }

          If a constant in a sub-interface replaces/shadows a constant in a super interface (both Java), when trying to access the sub-interface's constant value from Groovy, the behaviour is intermittantly incorrect - sometimes the sub-interface's value is returned (correct) and sometimes the super interface's value is returned (incorrect).
          In Java the sub-interface's value is always returned, as expected.

          See source code below that demonstrates this: InterfaceA.java, InterfaceB.java, ShowBugGroovy.groovy, ShowBugJava.java
          If ShowBugGroovy is repeatedly run, sometimes the assertion fails, sometimes it passes (randomly?). I believe the behaviour is the same for concrete implementations of the sub-interface.

          {code}
          package groovybug;

          public interface InterfaceA {
              String FOO="Foo A";
          }
          {code}

          {code}
          package groovybug;

          public interface InterfaceB extends InterfaceA {
              String FOO="Foo B";
          }
          {code}

          {code}
          package groovybug

          class ShowBugGroovy {
              static main(args) {
                  println("Interface A: " + InterfaceA.FOO);
                  println("Interface B: " + InterfaceB.FOO);

                  // Fails randomly
                  assert(InterfaceA.FOO!=InterfaceB.FOO)
              }
          }
          {code}

          {code}
          package groovybug;

          public class ShowBugJava {
              public static void main(String[] args) {
                  System.out.println("Interface A: " + InterfaceA.FOO);
                  System.out.println("Interface B: " + InterfaceB.FOO);

                  // Always passes
                  assert(!InterfaceA.FOO.equals(InterfaceB.FOO));
              }
          }
          {code}
          CÚdric Champeau made changes -
          Assignee Cedric Champeau [ melix ]
          CÚdric Champeau made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Fix Version/s 2.0-beta-3 [ 18244 ]
          Fix Version/s 1.8.6 [ 18245 ]
          Resolution Fixed [ 1 ]
          CÚdric Champeau made changes -
          Resolution Fixed [ 1 ]
          Status Resolved [ 5 ] Reopened [ 4 ]
          Guillaume Laforge made changes -
          Fix Version/s 1.8.7 [ 18317 ]
          Fix Version/s 1.8.6 [ 18245 ]
          CÚdric Champeau made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          CÚdric Champeau made changes -
          Resolution Fixed [ 1 ]
          Status Resolved [ 5 ] Reopened [ 4 ]
          CÚdric Champeau made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Fix Version/s 1.8.6 [ 18245 ]
          Fix Version/s 1.8.7 [ 18317 ]
          Resolution Fixed [ 1 ]
          CÚdric Champeau made changes -
          Link This issue is related to GROOVY-5335 [ GROOVY-5335 ]
          Paul King made changes -
          Status Resolved [ 5 ] Closed [ 6 ]

            People

            • Assignee:
              CÚdric Champeau
              Reporter:
              Stephen Summerfield
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: