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

Reflection member filtering registration might be flawed

XMLWordPrintable

    • Cause Known
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      The dynamic registration of members to filter on jdk.internal.reflect.Reflection through registerFieldsToFilter(...) and registerMethodsToFilter(...) (see JDK-8210496) might be flawed.
      Because these methods are executed in the static initializers of the respective classes, accessing the class without initializing it prevents the registration of the filters.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Finding the method `getUnsafe` should fail
      ACTUAL -
      It does not fail, unless Unsafe has been initialized before

      ---------- BEGIN SOURCE ----------
      public class ReflectionFilteringTest {
          public static void main(String[] args) throws Exception {
              boolean initialize = false;
              Class<?> c = Class.forName("sun.misc.Unsafe", initialize, ReflectionFilteringTest.class.getClassLoader());
              
              // This should fail because getUnsafe is supposed to be filtered
              // But it does not fail if Unsafe has not been initialized yet
              Method m = c.getDeclaredMethod("getUnsafe");
              System.out.println(m);
          }
      }
      ---------- END SOURCE ----------

            liach Chen Liang
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: