-
Notifications
You must be signed in to change notification settings - Fork 300
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
Class references in lambdas not found #992
Comments
I can confirm that class LambdaTest {
Runnable get() {
return () -> System.out.println("Hello from `LambdaTest.lambda$get$0()`");
}
}
assertThat(new ClassFileImporter().importClass(LambdaTest.class).getCodeUnits())
.extracting(JavaCodeUnit::getFullName)
.hasSize(3); // LambdaTest.<init>, LambdaTest.get(), LambdaTest.lambda$get$0() changed to As |
Thanks for reporting this, this seems to be actually a bug 🙈 AFAIS referenced class objects (and also instanceof checks for that matter) are bypassing the lambda resolution logic. I'll try to fix that ASAP and release a bugfix version! |
Thanks for your effort, @codecholeric! I'm looking forward to the bugfix release. |
When we improved importing lambdas in a404fb4 we overlooked that there can also other dependencies than regular accesses be declared within the body of a lambda, namely references to class objects and instanceof checks. Since we completely removed the synthetic methods from the import but didn't resolve the origin of those dependencies against the correct (lambda-declaring) method these dependencies were now missing completely from the import. We now fix this by applying the same origin resolution mechanism to those dependencies and associate them with the method that originally declares the lambda. Resolves: #992
Since version 1.0.0, the method
JavaClass#getDirectDependenciesFromSelf
no longer finds classes referenced in lambdas.Unit-Test to reproduce the problem:
While the Number.class and Optional.class are found, the String.class referenced in a lambda is not found:
This used to work as expected with version 0.23.1.
It could be related to #847, but I cannot see an obvious reason.
Thanks for looking into this!
The text was updated successfully, but these errors were encountered: