Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8013530

Invalid values cached for public fields of classes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • tbd
    • 7, 8
    • core-libs
    • None

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      When calculating public fields of a class " Foo " which is extending a class " Baa " , the public fields of " Baa " are calculated in a recursive call
      skipping those parent interfaces that have allready been calculated for class " Foo " .

      Nevertheless, the reduced set of fields recursivly calculated for " Baa " is stored in " Baa " 's own static cache and will be retured on a direct " getFields() " call on " Baa.class " not including those parent interfaces of " Foo " skipped earlier.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try example code with " TRY_WITH_AND_WITHOUT = true " and then with
       " TRY_WITH_AND_WITHOUT = false " . That leads to diffferent results although the output must be the same.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      With " TRY_WITH_AND_WITHOUT = false " :

      Class C has the follwing fields: CD
      Class C should have the follwing fields: CD

      With " TRY_WITH_AND_WITHOUT = true " :

      Class C has the follwing fields: CD
      Class C should have the follwing fields: CD

      ACTUAL -
      With " TRY_WITH_AND_WITHOUT = false " (correct result):

      Class C has the follwing fields: CD
      Class C should have the follwing fields: CD

      With " TRY_WITH_AND_WITHOUT = true " (wrong result):

      Class C has the follwing fields: C
      Class C should have the follwing fields: CD


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.lang.reflect.Field;

      public class Main
      {
      public interface A extends B, C
      {
      public static final String A = " a " ;
      }

      public interface B extends D
      {
      public static final String B = " b " ;
      }

      public interface C extends D
      {
      public static final String C = " c " ;
      }

      public interface D
      {
      public static final String D = " d " ;
      }

      public static void main(String[] args) throws Exception
      {
      boolean TRY_WITH_AND_WITHOUT = true;

      if (TRY_WITH_AND_WITHOUT)
      {
      A.class.getFields();
      }

      System.out.print( " Class C has the following fields: " );

      for (Field field : C.class.getFields())
      {
      System.out.print(field.getName());
      }

      System.out.println();
      System.out.println( " Class C should have the following fields: CD " );
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Set the system property " -Dsun.reflect.noCaches=true " .

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: