Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where call origins cannot be found on descriptor signature mismatch #812

Conversation

codecholeric
Copy link
Collaborator

With ArchUnit 0.23.0 we fixed an ambiguity problem when resolving method call origins (bridge methods would cause two methods with same name and parameter types, so we would pick one randomly, which could be the wrong/synthetic one). Unfortunately, this broke some Kotlin use cases, because inline functions would cause the compiler to create synthetic classes with methods where the signature and the descriptor do not match (e.g. the signature says the return type is String, but the descriptor claims Object). In these cases the erasure of the generic type does not match the raw type. But so far for the return type we derived the raw return type as erasure from the generic return type.
This is now fixed by keeping raw and generic return type completely separate, since we obviously cannot derive one from the other (the JVM spec also clearly states that this is a valid case, that descriptor and signature do not need to match exactly and are not validated against each other).

Resolves: #804
Resolves: #807
Resolves: #802

This task depends on the compiled output of the `compileJava` task, so we should explicitly declare this dependency. Otherwise, if you just run `compileJdk9mainJava` on a clean build it breaks.

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
In the end this is not relevant for most users which will be happy with the default configuration and do not need to get into the depths of tweaking specific resolutions.

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
@hankem hankem self-requested a review February 27, 2022 08:13
With ArchUnit 0.23.0 we fixed an ambiguity problem when resolving method call origins (bridge methods would cause two methods with same name and parameter types, so we would pick one randomly, which could be the wrong/synthetic one). Unfortunately, this broke some Kotlin use cases, because inline functions would cause the compiler to create synthetic classes with methods where the `signature` and the `descriptor` do not match (e.g. the signature says the return type is `String`, but the descriptor claims `Object`). In these cases the erasure of the generic type does not match the raw type. But so far for the return type we derived the raw return type as erasure from the generic return type.
This is now fixed by keeping raw and generic return type completely separate, since we obviously cannot derive one from the other (the JVM spec also clearly states that this is a valid case, that descriptor and signature do not need to match exactly and are not validated against each other).

Note that for parameter types we have already separated this a while ago, so there it never was a problem.

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
Since we meanwhile have the descriptor both on the search target and the code unit candidates, we can simply compare that instead of comparing raw parameter types and return type individually.

Note that this by itself would have already fixed the bug where call origins cannot be identified if descriptor and signature mismatch, but nevertheless the API would have been behaving wrongly when deriving the raw return type from the erasure of the generic return type.

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
@codecholeric codecholeric force-pushed the fix-bug-where-call-origins-cannot-be-found-on-descriptor-signature-mismatch branch from 0959f2c to 87f1b15 Compare February 27, 2022 09:45
@codecholeric codecholeric merged commit 246daae into release-0.23.0 Feb 27, 2022
@codecholeric codecholeric deleted the fix-bug-where-call-origins-cannot-be-found-on-descriptor-signature-mismatch branch February 27, 2022 11:30
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