JDK-5003235 : Accessibility of private inner class
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.4.2,6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2004-02-25
  • Updated: 2017-05-16
  • Resolved: 2005-01-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b19Fixed
Related Reports
Duplicate :  
Relates :  
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) 
======================================================================

Comments
SUGGESTED FIX Index: src/share/classes/com/sun/tools/javac/comp/Resolve.java ============================================================== @@ -184,6 +184,8 @@ || env.toplevel.packge == sym.packge()) && + isAccessible(env, site) + && sym.isInheritedIn(site.tsym, types); case PROTECTED: return @@ -197,6 +199,8 @@ // (but type names should be disallowed elsewhere!) env.info.selectSuper && (sym.flags() & STATIC) == 0 && sym.kind != TYP) && + isAccessible(env, site) + && // `sym' is accessible only if not overridden by // another symbol which is a member of `site' // (because, if it is overridden, `sym' is not strictly However, more work needs to be done for error messages. ###@###.### 2004-11-11 06:11:57 GMT
11-11-2004

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang
17-07-2004

PUBLIC COMMENTS ...
17-07-2004

EVALUATION Looks like a bug. ###@###.### 2004-02-25
25-02-2004