Harmony
  1. Harmony
  2. HARMONY-1309

[luni][tests] incorrect test for reflection access control

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Classlib
    • Labels:
      None

      Description

      There is a test[1] in classlib, which verifies that reflection access
      from enclosing class to a private member of a nested class results in
      IllegalAccessException.
      However, this is against the language specification (para 6.6.1 of the JLS3):
      "if the member or constructor is declared private, then access is
      permitted if and only if it occurs within the body of the top level class (7.6)
      that encloses the declaration of the member or constructor."

      Moreover, the following test reveals inconsistency between standard
      access control and reflective one:
      ---------------------------------
      class NestedAccessTest {
      static class A {
      private static int x = 123;
      }
      public static void main(String... s) throws Throwable{
      System.out.println(A.x);
      System.out.println(A.class.getDeclaredField("x").get(null));
      }
      }
      --------------------------------
      >java -showversion NestedAccessTest
      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)
      123
      Exception in thread "main" java.lang.IllegalAccessException: Class
      NestedAccessTest can not access a member of class NestedAccessTest$A
      with modifiers "private static"
      at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
      at java.lang.reflect.Field.doSecurityCheck(Field.java:954)
      at java.lang.reflect.Field.getFieldAccessor(Field.java:895)
      at java.lang.reflect.Field.get(Field.java:357)
      at NestedAccessTest.main(NestedAccessTest.java:7)
      ----------------------------------

      Besides, this is an acknowledged bug of RI [2], and is ranked TOP#6.

      [1]<testcase classname="tests.api.java.lang.reflect.FieldTest"
      name="test_getLjava_lang_Object"/>
      [2] http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4071957

      1. test-refl-acc.patch
        3 kB
        Alexey Varlamov
      2. test-refl-acc.patch
        3 kB
        Alexey Varlamov

        Issue Links

          Activity

          Hide
          Alexey Varlamov added a comment -

          Verified

          Show
          Alexey Varlamov added a comment - Verified
          Hide
          Alexei Zakharov added a comment -

          Alexey, thanks for the patch! Changes were applied at r474356. Please check.

          Show
          Alexei Zakharov added a comment - Alexey, thanks for the patch! Changes were applied at r474356. Please check.
          Hide
          Alexey Varlamov added a comment -

          More j9-friendly patch: commented out access check for nested member

          Show
          Alexey Varlamov added a comment - More j9-friendly patch: commented out access check for nested member
          Hide
          Alexei Fedotov added a comment -

          [drlvm][unit] Blocks http://wiki.apache.org/harmony/Unit_Tests_Pass_on_DRLVM

          This is a low risk test fix.

          Show
          Alexei Fedotov added a comment - [drlvm] [unit] Blocks http://wiki.apache.org/harmony/Unit_Tests_Pass_on_DRLVM This is a low risk test fix.
          Hide
          Alexey Varlamov added a comment -

          Probably we can (temporarily) comment out nested member access case, to avoid unexpected failures on IBM VME.

          Show
          Alexey Varlamov added a comment - Probably we can (temporarily) comment out nested member access case, to avoid unexpected failures on IBM VME.
          Hide
          Alexey Varlamov added a comment -

          The patch adds another check for top-level class member access violation (IllegalAccessException), and corrects nested member access case.

          Show
          Alexey Varlamov added a comment - The patch adds another check for top-level class member access violation (IllegalAccessException), and corrects nested member access case.

            People

            • Assignee:
              Alexei Zakharov
              Reporter:
              Alexey Varlamov
            • Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development