From 5200dce753ee25410608c8e78656854f0a876a68 Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Thu, 3 Dec 2020 18:44:17 -0600 Subject: [PATCH] GROOVY-9791 --- .../groovy/classgen/AsmClassGenerator.java | 3 ++- .../classgen/asm/sc/StaticTypesCallSiteWriter.java | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/base/org.codehaus.groovy25/src/org/codehaus/groovy/classgen/AsmClassGenerator.java b/base/org.codehaus.groovy25/src/org/codehaus/groovy/classgen/AsmClassGenerator.java index 35d955ed99..8e83fae7ca 100644 --- a/base/org.codehaus.groovy25/src/org/codehaus/groovy/classgen/AsmClassGenerator.java +++ b/base/org.codehaus.groovy25/src/org/codehaus/groovy/classgen/AsmClassGenerator.java @@ -936,7 +936,8 @@ public static boolean samePackages(final String pkg1, final String pkg2) { ); } - private static boolean isValidFieldNodeForByteCodeAccess(FieldNode fn, ClassNode accessingNode) { + // GRECLIPSE edit -- private->public + public static boolean isValidFieldNodeForByteCodeAccess(FieldNode fn, ClassNode accessingNode) { if (fn == null) return false; ClassNode declaringClass = fn.getDeclaringClass(); // same class is always allowed access diff --git a/base/org.codehaus.groovy25/src/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java b/base/org.codehaus.groovy25/src/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java index 0bbc546d80..58e9348e30 100644 --- a/base/org.codehaus.groovy25/src/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java +++ b/base/org.codehaus.groovy25/src/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java @@ -86,7 +86,6 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.args; import static org.codehaus.groovy.ast.tools.GeneralUtils.callX; import static org.codehaus.groovy.ast.tools.GeneralUtils.constX; -import static org.codehaus.groovy.classgen.AsmClassGenerator.samePackages; import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.chooseBestMethod; import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findDGMMethodsByNameAndArguments; import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf; @@ -561,10 +560,15 @@ private boolean makeGetPropertyWithGetter(final Expression receiver, final Class } boolean makeGetField(final Expression receiver, final ClassNode receiverType, final String fieldName, final boolean safe, final boolean implicitThis) { + /* GRECLIPSE edit -- GROOVY-7039, GROOVY-9791 FieldNode field = receiverType.getField(fieldName); // direct access is allowed if we are in the same class as the declaring class // or we are in an inner class if (field != null && isDirectAccessAllowed(field, controller.getClassNode())) { + */ + FieldNode field = org.apache.groovy.ast.tools.ClassNodeUtils.getField(receiverType, fieldName); + if (field != null && AsmClassGenerator.isValidFieldNodeForByteCodeAccess(field, controller.getClassNode())) { + // GRECLIPSE end CompileStack compileStack = controller.getCompileStack(); MethodVisitor mv = controller.getMethodVisitor(); ClassNode replacementType = field.getOriginType(); @@ -604,7 +608,7 @@ boolean makeGetField(final Expression receiver, final ClassNode receiverType, fi operandStack.replace(replacementType); return true; } - + /* GRECLIPSE edit for (ClassNode intf : receiverType.getInterfaces()) { // GROOVY-7039 if (intf != receiverType && makeGetField(receiver, intf, fieldName, safe, implicitThis)) { @@ -616,9 +620,11 @@ boolean makeGetField(final Expression receiver, final ClassNode receiverType, fi if (superClass != null) { return makeGetField(receiver, superClass, fieldName, safe, implicitThis); } + */ return false; } + /* GRECLIPSE edit -- GROOVY-9791 private static boolean isDirectAccessAllowed(FieldNode field, ClassNode receiver) { ClassNode declaringClass = field.getDeclaringClass().redirect(); ClassNode receiverType = receiver.redirect(); @@ -639,6 +645,7 @@ private static boolean isDirectAccessAllowed(FieldNode field, ClassNode receiver // finally public and visible return field.isPublic() || samePackages(receiver.getPackageName(), declaringClass.getPackageName()); } + */ @Override public void makeSiteEntry() { @@ -946,7 +953,7 @@ private boolean setField(PropertyExpression expression, Expression objectExpress return true; } - @SuppressWarnings("unused") + /* GRECLIPSE edit private boolean getField(PropertyExpression expression, Expression receiver, ClassNode receiverType, String name) { boolean safe = expression.isSafe(); boolean implicitThis = expression.isImplicitThis(); @@ -971,6 +978,7 @@ private boolean getField(PropertyExpression expression, Expression receiver, Cla } return false; } + */ private void addPropertyAccessError(final Expression receiver, final String propertyName, final ClassNode receiverType) { String receiverName = (receiver instanceof ClassExpression ? receiver.getType() : receiverType).toString(false);