Bug 15073 - Illegal access to package-private class is allowed
Summary: Illegal access to package-private class is allowed
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
Keywords: accepts-invalid, patch
Depends on:
Blocks: 13607
  Show dependency treegraph
Reported: 2004-04-22 14:00 UTC by Ranjit Mathew
Modified: 2004-05-06 17:57 UTC (History)
2 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2004-04-22 14:00:58


Note You need to log in before you can comment on or make changes to this bug.
Description Ranjit Mathew 2004-04-22 14:00:19 UTC
GCJ silently compiles an illegal access to a package-private
class in another package.

Here's the testcase:

------------------ Snafu.java -------------------------------
public class Snafu {
  public static void main( String[] args) {
    foo.Bar.hello( );

------------------ foo/Bar.java -----------------------------
package foo;

class Bar {
  public static void hello( ) { System.out.println( "Hello!"); }

Here's what JDK on Linux says for this:
Snafu.java:3: foo.Bar is not public in foo; cannot be accessed from outside pack
    foo.Bar.hello( );
Snafu.java:3: hello() in foo.Bar is not defined in a public class or interface;
cannot be accessed from outside package
    foo.Bar.hello( );
2 errors
Comment 1 Ranjit Mathew 2004-04-27 09:04:30 UTC
Patch awaiting review:
Comment 2 CVS Commits 2004-05-06 17:43:52 UTC
Subject: Bug 15073

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 3 Andrew Pinski 2004-05-06 17:57:31 UTC