java/8618: call to private constructor allowed for anonymous inner class

jmr@ugcs.caltech.edu jmr@ugcs.caltech.edu
Sun Nov 17 20:06:00 GMT 2002


>Number:         8618
>Category:       java
>Synopsis:       call to private constructor allowed for anonymous inner class
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          accepts-illegal
>Submitter-Id:   net
>Arrival-Date:   Sun Nov 17 20:06:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Jesse Rosenstock
>Release:        gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
>Organization:
>Environment:

>Description:
Calls to private constructors are (incorrectly) allowed when  creating an anonymous inner class.

; cat X.java
public class X {
    public static void main(String[] args) {
        // new Y();
        new Y() { };  // should be illegal
    }
}

; cat Y.java
public class Y {
    private Y() {
    }
}

; gcj X.java Y.java --main=X

gcj doesn't give an error, whereas Sun's javac does

; javac X.java
X.java:4: Y() has private access in Y
        new Y() { };
        ^
X.java:4: Y() has private access in Y
        new Y() { };
                ^
2 errors

If you switch around which line is commented out in X.main, then gcj correctly
gives an error:

gcj X.java Y.java --main=X
X.java:3: Can't access private constructor `Y.<init>' from `X'.
           new Y();
               ^
1 error
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Java-prs mailing list