This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Illegal Package-Private Accesses Yet Again!


Hi,

    As Michael and Mark have repeatedly pointed out, the fact
that GCJ still allows illegal package-private accesses lets
incorrect code to slip into libgcj, creating merge problems with
GNU Classpath.

Recently Per unwittingly committed such code for NIO.

We must fix this silly bug (PR java/9685) ASAP!

I have updated my package-private access patch to the current
mainline and have attached it with this mail.

With this patch, one finds:

1. java.lang.VMThrowable illegally accessses stackTraceAddrs()
   from gnu.gcj.runtime.StackTrace

2. READ, WRITE, APPEND, EXCL, SYNC, DSYNC and available() in
   gnu.java.nio.channels.FileChannelImpl are illegally accessed
   by java.io.FileInputStream, java.io.FileOutputStream and
   java.io.RandomAccessFile

3. gnu.gcj.runtime.NameFinder illegally accesses the constructor
   of java.lang.StackTraceElement

In a follow up mail, I will post a simple patch to avoid the errors
above, till such a time that Bryce/Per/Anyone Else can provide
a "proper" fix. Without that patch, this patch will not let bootstrap
finish.

Ranjit.

Index: ChangeLog
from  Ranjit Mathew  <rmathew@hotmail.com>

	PR java/9685
	* parse.y (java_acc_ctrl_str): New method.
	(not_accessible_field_error): Use java_acc_ctrl_str()
	instead of java_accstring_lookup().
	(resolve_qualified_expression_name): Likewise.
	(patch_method_invocation): Likewise.
	(not_accessible_p): Use DECL_CONTEXT (member) instead of
	reference for package-private access checking.

Index: parse.y
===================================================================
--- parse.y	2004-03-29 21:06:35.000000000 +0530
+++ parse.y	2004-03-29 22:16:25.000000000 +0530
@@ -77,4 +77,5 @@ definitions and other extensions.  */
 /* Local function prototypes */
 static char *java_accstring_lookup (int);
+static const char *java_acc_ctrl_str (int);
 static void  classitf_redefinition_error (const char *,tree, tree, tree);
 static void  variable_redefinition_error (tree, tree, tree, int);
@@ -3183,5 +3184,5 @@ not_accessible_field_error (tree wfl, tr
   parse_error_context 
     (wfl, "Can't access %s field `%s.%s' from `%s'",
-     java_accstring_lookup (get_access_flags_from_decl (decl)),
+     java_acc_ctrl_str (get_access_flags_from_decl (decl)),
      GET_TYPE_NAME (DECL_CONTEXT (decl)),
      IDENTIFIER_POINTER (DECL_NAME (decl)),
@@ -3229,4 +3230,14 @@ java_accstring_lookup (int flags)
 }
 
+static const char *
+java_acc_ctrl_str (int flags)
+{
+  if (flags & ACC_PRIVATE) return "private";
+  if (flags & ACC_PROTECTED) return "protected";
+  if (flags & ACC_PUBLIC) return "public";
+  
+  return "package-private";
+}
+
 /* Issuing error messages upon redefinition of classes, interfaces or
    variables. */
@@ -9874,5 +9885,5 @@ resolve_qualified_expression_name (tree 
 	      parse_error_context
 		(qual_wfl, "Can't access %s class '%s' from '%s'",
-		 java_accstring_lookup (get_access_flags_from_decl (decl)),
+		 java_acc_ctrl_str (get_access_flags_from_decl (decl)),
 		 IDENTIFIER_POINTER (DECL_NAME (decl)),
 		 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))));
@@ -10141,9 +10152,10 @@ not_accessible_p (tree reference, tree m
     }
 
-  /* Default access are permitted only when occurring within the
-     package in which the type (REFERENCE) is declared. In other words,
-     REFERENCE is defined in the current package */
-  if (ctxp->package)
-    return !class_in_current_package (reference);
+  /* Default access is permitted only when occurring from within the
+     package in which the context (MEMBER) is declared. */
+  if (TREE_CODE (member) == TYPE_DECL)
+    return !class_in_current_package (TREE_TYPE (member));
+  else
+    return !class_in_current_package (DECL_CONTEXT (member));
 
   /* Otherwise, access is granted */
@@ -10541,5 +10553,5 @@ patch_method_invocation (tree patch, tre
       const char *const fct_name = IDENTIFIER_POINTER (DECL_NAME (list));
       const char *const access =
-	java_accstring_lookup (get_access_flags_from_decl (list));
+	java_acc_ctrl_str (get_access_flags_from_decl (list));
       const char *const klass =
 	IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (list))));


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]