blackdrag commented on code in PR #3097:
URL: https://github.com/apache/groovy/pull/3097#discussion_r4429126084


##########
src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java:
##########
@@ -1307,9 +1307,52 @@ private static String getStaticFieldName(final ClassNode 
type) {
     /**
      * Determines if the given field can be directly accessed by the given 
class
      * (via {@code GETFIELD}, {@code GETSTATIC}, etc. bytecode instructions).
+     * <p>
+     * A protected or package-private field of a class with the same package
+     * name is accessible only within the same run-time package; see
+     * {@link #isInSameRuntimePackage}. Otherwise it is directly accessible
+     * only through the subclass rule for a protected field.
      */
     public static boolean isFieldDirectlyAccessible(final FieldNode field, 
final ClassNode accessingClass) {
-        return field != null && 
isMemberDirectlyAccessible(field.getModifiers(), field.getDeclaringClass(), 
accessingClass);
+        if (field == null || !isMemberDirectlyAccessible(field.getModifiers(), 
field.getDeclaringClass(), accessingClass)) return false;
+        ClassNode declaringClass = field.getDeclaringClass();
+        return field.isPublic() || field.isPrivate() || 
isInSameRuntimePackage(declaringClass, accessingClass)
+            || (field.isProtected() && 
accessingClass.isDerivedFrom(declaringClass));

Review Comment:
   this overlaps highly with isMemberDirectlyAccessible I don`t think all 
conditions make sense. The later condition needs at least some comments on why 
they are now legal cases and how they overlap with the illegal cases that have 
been excluded



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to