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
@@ -404,26 +405,27 @@ private void checkMethodsForWeakerAccess(final ClassNode cn) {
404
405
405
406
private void checkMethodsForOverridingFinal (final ClassNode cn ) {
406
407
for (MethodNode method : cn .getMethods ()) {
408
+ if ((method .getModifiers () & ACC_SYNTHETIC ) != 0 ) continue ; // GROOVY-11579: bridge method
409
+
410
+ ClassNode sc = cn .getSuperClass ();
407
411
Parameter [] params = method .getParameters ();
408
- for (MethodNode superMethod : cn .getSuperClass ().getMethods (method .getName ())) {
409
- Parameter [] superParams = superMethod .getParameters ();
410
- if (!ParameterUtils .parametersEqual (params , superParams )) continue ;
411
- if (!superMethod .isFinal ()) break ;
412
- addInvalidUseOfFinalError (method , params , superMethod .getDeclaringClass ());
413
- return ;
412
+ for (MethodNode superMethod : sc .getMethods (method .getName ())) {
413
+ if (superMethod .isFinal ()
414
+ && ParameterUtils .parametersEqual (params , superMethod .getParameters ())) {
415
+ StringBuilder sb = new StringBuilder ();
416
+ sb .append ("You are not allowed to override the final method " );
417
+ sb .append (method .getName ());
418
+ appendParamsDescription (params , sb );
419
+ sb .append (" from " );
420
+ sb .append (getDescription (sc ));
421
+ sb .append ("." );
422
+
423
+ addError (sb .toString (), method .getLineNumber () > 0 ? method : cn );
424
+ }
414
425
}
415
426
}
416
427
}
417
428
418
- private void addInvalidUseOfFinalError (final MethodNode method , final Parameter [] parameters , final ClassNode superCN ) {
419
- StringBuilder msg = new StringBuilder ();
420
- msg .append ("You are not allowed to override the final method " ).append (method .getName ());
421
- appendParamsDescription (parameters , msg );
422
- msg .append (" from " ).append (getDescription (superCN ));
423
- msg .append ("." );
424
- addError (msg .toString (), method );
425
- }
426
-
427
429
private void appendParamsDescription (final Parameter [] parameters , final StringBuilder msg ) {
428
430
msg .append ('(' );
429
431
boolean needsComma = false ;
@@ -450,6 +452,7 @@ private void addWeakerAccessError(final ClassNode cn, final MethodNode method, f
450
452
msg .append (superMethod .getDeclaringClass ().getName ());
451
453
msg .append ("; attempting to assign weaker access privileges; was " );
452
454
msg .append (superMethod .isPublic () ? "public" : (superMethod .isProtected () ? "protected" : "package-private" ));
455
+
453
456
addError (msg .toString (), method );
454
457
}
455
458
0 commit comments