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

Accessibility of private inner class

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 1.4.2, 6
    • Fix Version/s: 6
    • Component/s: tools
    • Subcomponent:
    • Resolved In Build:
      b19
    • CPU:
      generic, x86
    • OS:
      generic, windows_xp
    • Verification:
      Verified

      Description



      Name: jl125535 Date: 02/25/2004


      FULL PRODUCT VERSION :
      java version "1.4.2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
      Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

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


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :

      // Outer.java
      class Outer
      {
          public Inner inner;

          public void create()
          {
              inner = new Inner();
          }

          private class Inner
          {
              protected int k = 100;
          }
      }

      // Access.java
      class Access
      {
          public static void main(String[] args)
          {
              Outer outer = new Outer();
              outer.create();
              System.out.println("Value of k: " + outer.inner.k);
          }
      }


      The code compiles and runs without any errors.
      But actually it should'nt because the inner class "Inner" is declared private and is accessed from outside the enclosing class. If the declaration inside the inner class is changed from "protected int k = 100;" to "public int k = 100;" the compiler gives an error because the inner class is declared as being private.
      That's what is expected to happen for the "protected int k = 100;" as well.
      The same problem occurs if the inner class is declared with default/package
      visibility.

      Many users in the forum report the same problem for j2sdk 1.4.1 and j2sdk 1.4.2. See http://forum.java.sun.com/thread.jsp?forum=31&thread=487351&tstart=0&trange=500.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      see above

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      a compiler error

      ACTUAL -
      Value of k: 100

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      see above
      ---------- END SOURCE ----------
      (Incident Review ID: 236850)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ahe Peter Ahe
                Reporter:
                jleesunw Jon Lee (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: