@@ -434,7 +434,7 @@ public String visit(ClassMetadata c, String origName, boolean isInterfaceOfAnces
434
434
}, true , false /* JVM spec says: interfaces after superclasses */ );
435
435
}
436
436
437
- private String checkFieldAccess (String owner , final String field , final boolean callIsVirtual ) {
437
+ private String checkFieldAccess (String owner , final String field ) {
438
438
String violation = checkClassUse (owner , "class/interface" , owner );
439
439
if (violation != null ) {
440
440
return violation ;
@@ -454,10 +454,9 @@ public String visit(ClassMetadata c, String origName, boolean isInterfaceOfAnces
454
454
if (!c .fields .contains (field )) {
455
455
return null ;
456
456
}
457
- // is we have a virtual call, look into superclasses, otherwise stop:
458
- final String notFoundRet = callIsVirtual ? null : AncestorVisitor .STOP ;
457
+ // we found the field: from now on we use STOP to exit, because fields are not virtual!
459
458
if (previousInRuntime && c .isNonPortableRuntime ) {
460
- return notFoundRet ; // something inside the JVM is extending internal class/interface
459
+ return STOP ; // something inside the JVM is extending internal class/interface
461
460
}
462
461
String violation = forbiddenSignatures .checkField (c .className , field );
463
462
if (violation != null ) {
@@ -470,7 +469,8 @@ public String visit(ClassMetadata c, String origName, boolean isInterfaceOfAnces
470
469
return violation ;
471
470
}
472
471
}
473
- return notFoundRet ;
472
+ // we found the field and as those are not virtual, there is no need to go up in class hierarchy:
473
+ return STOP ;
474
474
}
475
475
}, true , true /* JVM spec says: superclasses after interfaces */ );
476
476
}
@@ -479,10 +479,9 @@ private String checkHandle(Handle handle, boolean checkLambdaHandle) {
479
479
switch (handle .getTag ()) {
480
480
case Opcodes .H_GETFIELD :
481
481
case Opcodes .H_PUTFIELD :
482
- return checkFieldAccess (handle .getOwner (), handle .getName (), true );
483
482
case Opcodes .H_GETSTATIC :
484
483
case Opcodes .H_PUTSTATIC :
485
- return checkFieldAccess (handle .getOwner (), handle .getName (), false );
484
+ return checkFieldAccess (handle .getOwner (), handle .getName ());
486
485
case Opcodes .H_INVOKEVIRTUAL :
487
486
case Opcodes .H_INVOKESTATIC :
488
487
case Opcodes .H_INVOKESPECIAL :
@@ -560,8 +559,7 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc,
560
559
561
560
@ Override
562
561
public void visitFieldInsn (int opcode , String owner , String name , String desc ) {
563
- final boolean callIsVirtual = (opcode == Opcodes .GETFIELD ) || (opcode == Opcodes .PUTFIELD );
564
- reportMethodViolation (checkFieldAccess (owner , name , callIsVirtual ), "method body" );
562
+ reportMethodViolation (checkFieldAccess (owner , name ), "method body" );
565
563
}
566
564
567
565
@ Override
0 commit comments