-
Bug
-
Resolution: Fixed
-
P2
-
1.4.2, 6
-
b19
-
generic, x86
-
generic, windows_xp
-
Verified
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)
======================================================================
- duplicates
-
JDK-6193187 Private inner class accessible from subclasses
- Closed
- relates to
-
JDK-6197664 l10n for 6182630: 1 resource updated in compiler.properties
- Resolved