Bug 12361

Summary: No error on illegal access to private inner class.
Product: gcc Reporter: Ralph Loader <suckfish>
Component: javaAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs, java-prs
Priority: P2 Keywords: accepts-invalid
Version: 3.4.0   
Target Milestone: 4.0.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2004-05-21 02:37:46
Bug Depends on:    
Bug Blocks: 13607    

Description Ralph Loader 2003-09-22 05:20:30 UTC
/*

Access checks appear not to be made when accessing inner classes.

This code should not compile, but does, both with 3.3.1 and trunk as
of 2003-9-21.

It should not be possible to access C outside of B.  Therefore
S.C.i below should give an error.

Sun javac does give an error:

$ /usr/java/j2sdk1.4.2/bin/javac temp.java
temp.java:35: B.S.C has private access in B.S
        return S.C.i;
                ^
1 error

*/

package B;

class S
{
    private static class C
    {
	static final int i = 1;
    }
}

class D
{
    int foo()
    {
	return S.C.i;
    }
}
Comment 1 Ralph Loader 2003-09-22 05:22:30 UTC
That should be '... outside of S' not '... outside of B'.
Comment 2 Andrew Pinski 2003-09-22 05:30:46 UTC
Related to bug 9685 and bug 9547 and bug 1333.
Comment 3 Ralph Loader 2003-09-22 05:43:43 UTC
Similarly, accessing a non-public class (e.g., A.Foo) from a class in a
different package (e.g., class B.Bar) does not give an error, but should.

/******** file Bar.java **********/
package B;
 
class Bar {
     
    A.Foo Basic()
    {
	return new A.Foo();
    }
 
}

/********** file Foo.java *********/
package A;

class Foo
{
}
Comment 4 Andrew Pinski 2003-09-27 04:53:25 UTC
I can confirm this on the mainline (20030926).
Comment 5 Andrew Pinski 2004-07-23 09:28:02 UTC
Fixed in 3.5.0.