Bug 9685

Summary: Illegal access to package-private method is allowed
Product: gcc Reporter: rmathew
Component: javaAssignee: Not yet assigned to anyone <unassigned>
Severity: normal CC: gcc-bugs, java-prs, pinskia
Priority: P3 Keywords: accepts-invalid, patch
Version: 3.3   
Target Milestone: 4.0.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2003-11-24 10:29:14
Bug Depends on:    
Bug Blocks: 13607    

Description rmathew 2003-02-13 06:16:01 UTC
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"



gcj -C foo/Bar.java
gcj -C ChkAcc.java
Comment 1 Andrew Pinski 2003-06-05 15:48:11 UTC
Still busted on the mainline (20030604).
Comment 2 rmathew 2003-07-22 12:31:23 UTC
The following kludge/patch to 3.3 (also verified on 3.4) catches most
of these errors:

Comment 3 Andrew Pinski 2003-11-24 10:29:13 UTC
Most likely the same bug as PR 13098 (which I filed).
Comment 4 Ranjit Mathew 2004-04-27 09:03:11 UTC
Patch awaiting review:
Comment 5 Ranjit Mathew 2004-04-27 09:06:48 UTC
*** Bug 13098 has been marked as a duplicate of this bug. ***
Comment 6 CVS Commits 2004-05-06 17:43:52 UTC
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().


Comment 7 Andrew Pinski 2004-05-06 17:57:46 UTC