74
74
import static org .objectweb .asm .Opcodes .ACC_STATIC ;
75
75
import static org .objectweb .asm .Opcodes .ACC_STRICT ;
76
76
import static org .objectweb .asm .Opcodes .ACC_SYNCHRONIZED ;
77
+ import static org .objectweb .asm .Opcodes .ACC_SYNTHETIC ;
77
78
import static org .objectweb .asm .Opcodes .ACC_TRANSIENT ;
78
79
import static org .objectweb .asm .Opcodes .ACC_VOLATILE ;
79
80
@@ -432,26 +433,27 @@ private void checkMethodsForWeakerAccess(final ClassNode cn) {
432
433
433
434
private void checkMethodsForOverridingFinal (final ClassNode cn ) {
434
435
for (MethodNode method : cn .getMethods ()) {
436
+ if ((method .getModifiers () & ACC_SYNTHETIC ) != 0 ) continue ; // GROOVY-11579: bridge method
437
+
438
+ ClassNode sc = cn .getSuperClass ();
435
439
Parameter [] params = method .getParameters ();
436
- for (MethodNode superMethod : cn .getSuperClass ().getMethods (method .getName ())) {
437
- Parameter [] superParams = superMethod .getParameters ();
438
- if (!ParameterUtils .parametersEqual (params , superParams )) continue ;
439
- if (!superMethod .isFinal ()) break ;
440
- addInvalidUseOfFinalError (method , params , superMethod .getDeclaringClass ());
441
- return ;
440
+ for (MethodNode superMethod : sc .getMethods (method .getName ())) {
441
+ if (superMethod .isFinal ()
442
+ && ParameterUtils .parametersEqual (params , superMethod .getParameters ())) {
443
+ StringBuilder sb = new StringBuilder ();
444
+ sb .append ("You are not allowed to override the final method " );
445
+ sb .append (method .getName ());
446
+ appendParamsDescription (params , sb );
447
+ sb .append (" from " );
448
+ sb .append (getDescription (sc ));
449
+ sb .append ("." );
450
+
451
+ addError (sb .toString (), method .getLineNumber () > 0 ? method : cn );
452
+ }
442
453
}
443
454
}
444
455
}
445
456
446
- private void addInvalidUseOfFinalError (final MethodNode method , final Parameter [] parameters , final ClassNode superCN ) {
447
- StringBuilder msg = new StringBuilder ();
448
- msg .append ("You are not allowed to override the final method " ).append (method .getName ());
449
- appendParamsDescription (parameters , msg );
450
- msg .append (" from " ).append (getDescription (superCN ));
451
- msg .append ("." );
452
- addError (msg .toString (), method );
453
- }
454
-
455
457
private void appendParamsDescription (final Parameter [] parameters , final StringBuilder msg ) {
456
458
msg .append ('(' );
457
459
boolean needsComma = false ;
@@ -478,6 +480,7 @@ private void addWeakerAccessError(final ClassNode cn, final MethodNode method, f
478
480
msg .append (superMethod .getDeclaringClass ().getName ());
479
481
msg .append ("; attempting to assign weaker access privileges; was " );
480
482
msg .append (superMethod .isPublic () ? "public" : (superMethod .isProtected () ? "protected" : "package-private" ));
483
+
481
484
addError (msg .toString (), method );
482
485
}
483
486
0 commit comments