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

(reflect) Inner objects should have access via reflection to private fields

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 1.4.0
    • core-libs
    • Fix Understood
    • generic
    • generic



      Name: nt126004 Date: 10/29/2001


      java version "1.4.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta2-b77)
      Java HotSpot(TM) Client VM (build 1.4.0-beta2-b77, mixed mode)

      Inner objects can access fields of the outer object.
      However, when an inner object tries to access the value of a field
      of its outer object via reflection, Field.getInt( this$0 ) throws
      an unjustified IllegalAccessException.

      Access control should be identical regardless of the access method, i.e.
      regardless of whether reflection is used or not.

      1. Run the following source code and the run time engine throws an unjustified
      IllegalAccessException.

      2. import java.io.*;
      import java.lang.reflect.*;

      public class test {
          public static void main( String[] args ) {
              test t = new test();
              t.newInner().accessFromInner();
          }
                  
          private int i = 1;
          
          public inner newInner() { return new inner(); }
          
          class inner {
              public void accessFromInner() {
                  try {
                      i = 0;
                      System.out.println( test.class.getDeclaredField("i").getInt(
      this$0 ) );
                  } catch( Exception e ) {
                      System.out.println( e );
                  }
              }
          }

      }

      3. java.lang.IllegalAccessException: test occurs
      (Review ID: 134531)
      ======================================================================

            Unassigned Unassigned
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: