Bug 12361 - No error on illegal access to private inner class.
Summary: No error on illegal access to private inner class.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks: 13607
  Show dependency treegraph
 
Reported: 2003-09-22 05:20 UTC by Ralph Loader
Modified: 2004-07-23 09:28 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-05-21 02:37:46


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.