Uploaded image for project: 'Code Tools'
  1. Code Tools
  2. CODETOOLS-6857029

Overlapping final static fields are not handled correctly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • st2.2
    • st2.2
    • tools
    • None
    • b03
    • x86
    • linux
    • Verified

      The situation when a successor class declares a constant with existed name:

          class A {
              public final static int F = 11;
          }

          class B extends A {
              public final static int F = 33;

          }
      is not handled correctly.

      SigTest produces the sig file as follows:
      ---
      CLSS public test.A
      cons public A()
      fld public final static int F = 11
      supr java.lang.Object

      CLSS public test.B
      cons public B()
      fld public final static int F = 33
      supr test.A
      ---

      When the class B is scanned two fields will be found:
        public static final int A.F: 11
        public static final int B.F: 33
      and both of them will be added to the class model with the same name. When the class model is asked to find field by name the first one will be returned.
      Depending on the order fields appear in class.getFields() test will either pass or fail.

      This situation is triggered by Bluray CTS where java.awt.event.KeyEvent is extended by
      org.havi.ui.event.HRcEvent and both classes define their own public static final field VK_STOP with different values.
      Trying fix for narrow case of testing only org.havi.ui.event.HRcEvent class signatures it works well.
      However it fails with another kind of failure for wider case of testing org.havi.ui.event package.

      ---------------
      Changed class org.havi.ui.event.HKeyEvent
        Missing Fields
          field public final static int org.havi.ui.event.HRcEvent.VK_STOP = 413
      ---------------

      To demonstrate new failure following test cases are added to Bluray CTS (see attached Blusig.test.xml):

          <TestCase ID="org_havi_ui_event">
              <CodeSet>
                  <ExecuteArgs>bdj_org -Package org.havi.ui.event</ExecuteArgs>
              </CodeSet>
          </TestCase>

          <TestCase ID="org_havi_HRcEvent">
              <CodeSet>
                  <ExecuteArgs>bdj_org -Package org.havi.ui.event.HRcEvent</ExecuteArs>
              </CodeSet>
          </TestCase>

      Yet some output is added to BlusigTest.java (file is attached) to make sure HRcEvent.VK_STOP exists indeed:

      Class hrcEvent = null;
      try {
          hrcEvent = Class.forName("org.havi.ui.event.HRcEvent");
          log.println("hrcEvent: " + hrcEvent);
      } catch (ClassNotFoundException e) {
          log.println("Could not find class HRcEvent: " + e);
      }

      try {
          java.lang.reflect.Field vkStop = hrcEvent.getField("VK_STOP");
          log.println("vkStop: " + vkStop);
      } catch (NoSuchFieldException e) {
          log.println("Could not find field: " + e);
      }

      java.lang.reflect.Field fields[] = hrcEvent.getFields();
      for (int i=0; i<fields.length; i++) {
          if (fields[i] == null) {
              log.println("field is null at index " + i);
              continue;
          }

          String name = fields[i].getName();

          if (name == null) {
              log.println("name is null at index " + i);
              continue;
          }

          if (name.endsWith("VK_STOP")) {
              log.println("field: " + fields[i]);
          }
      }


      Two btr files are attached:
      org_havi_HRcEvent - 288.btr
      org_havi_ui_event - 289.btr

            dfazunen Dmitry Fazunenko (Inactive)
            sreznick Sergey Reznick (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: