Skip to content

Exclude annotation members from aggressive overloading#453

Merged
piazzesiNiccolo-GS merged 2 commits intoGuardsquare:masterfrom
Nolij:master
Aug 11, 2025
Merged

Exclude annotation members from aggressive overloading#453
piazzesiNiccolo-GS merged 2 commits intoGuardsquare:masterfrom
Nolij:master

Conversation

@Nolij
Copy link
Copy Markdown
Contributor

@Nolij Nolij commented Dec 11, 2024

Aggressive overloading class members of annotations can cause errors like this:

Caused by: java.lang.annotation.AnnotationFormatError: java.lang.IllegalArgumentException: methods with same signature a() but incompatible return types: boolean and others
	at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:78)
	at java.base/java.lang.reflect.Field.declaredAnnotations(Field.java:1211)
	at java.base/java.lang.reflect.Field.declaredAnnotations(Field.java:1209)
	at java.base/java.lang.reflect.Field.getAnnotation(Field.java:1176)

This PR excludes annotation class members from aggressive overloading, allowing them to still be obfuscated and for the rest of a project to have aggressive overloading enabled.

@sonarqubecloud
Copy link
Copy Markdown

@Nolij
Copy link
Copy Markdown
Contributor Author

Nolij commented Aug 7, 2025

Is there a problem with how the fix for this bug has been implemented? I'd very much like to be able to enable aggressive overloading for one of my projects, and this bug is the only thing preventing me from doing so.

@piazzesiNiccolo-GS
Copy link
Copy Markdown
Contributor

Hi, thanks for the PR! Apologies for the waiting time.

Do you have a minimal reproduction of the issue that help us understand how you encountered this?

Code looks good, but can you also add an accompanying test?

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Aug 9, 2025

@Nolij
Copy link
Copy Markdown
Contributor Author

Nolij commented Aug 9, 2025

Hi, thanks for the PR! Apologies for the waiting time.

Do you have a minimal reproduction of the issue that help us understand how you encountered this?

Code looks good, but can you also add an accompanying test?

The issue should occur when the JVM attempts to classload any annotation class with multiple fields which has been aggressively overloaded. The unit test I added contains one such annotation class.

@piazzesiNiccolo-GS piazzesiNiccolo-GS merged commit 4781f58 into Guardsquare:master Aug 11, 2025
4 checks passed
@piazzesiNiccolo-GS
Copy link
Copy Markdown
Contributor

The unit test I added contains one such annotation class.

Perfect, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants