GCJ 3.3 seems to allow a class to access the package-private methods of a different class even though this is not permitted by the JLS. Here's a simple testcase: ------------------- File: foo/Bar.java -------------------- package foo; public class Bar { static void snafu( ) { } } ---------------------------- 8< ---------------------------- ------------------- File: ChkAcc.java ---------------------- public class ChkAcc { public void checkAccess( ) { foo.Bar.snafu( ); } } ---------------------------- 8< ---------------------------- GCJ wrongly allows ChkAcc.java to compile successfully. Note that this works with non-static methods as well. It also works if a class in a named package accesses package-private methods in the anonymous "default" package. Ranjit. Release: 3.3 How-To-Repeat: gcj -C foo/Bar.java gcj -C ChkAcc.java
Still busted on the mainline (20030604).
The following kludge/patch to 3.3 (also verified on 3.4) catches most of these errors: http://gcc.gnu.org/ml/java/2003-06/msg00300.html
Most likely the same bug as PR 13098 (which I filed).
Patch awaiting review: http://gcc.gnu.org/ml/java-patches/2004-q2/msg00230.html
*** Bug 13098 has been marked as a duplicate of this bug. ***
Subject: Bug 9685 CVSROOT: /cvs/gcc Module name: gcc Changes by: rmathew@gcc.gnu.org 2004-05-06 17:43:48 Modified files: gcc/java : ChangeLog parse.y Log message: Fixes PR java/9685, PR java/15073 * parse.y (accessibility_string): New method. (not_accessible_field_error): Use accessibility_string() instead of java_accstring_lookup(). (resolve_qualified_expression_name): Check with check_pkg_class_access() before allowing access using qualified names. Fix comment typo. Use check_pkg_class_access() instead of not_accessible_p() for unqualified types. (not_accessible_p): Use DECL_CONTEXT (member) instead of REFERENCE for package-private access checking. (patch_method_invocation): Use accessibility_string() instead of java_accstring_lookup(). Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&r1=1.1359&r2=1.1360 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/parse.y.diff?cvsroot=gcc&r1=1.475&r2=1.476
Fixed.