Skip to content

Commit

Permalink
GROOVY-9791
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Dec 4, 2020
1 parent d25cc4c commit 5200dce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)) {
Expand All @@ -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();
Expand All @@ -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() {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit 5200dce

Please sign in to comment.