Skip to content

Conversation

@timtebeek
Copy link
Member

What's your motivation?

ReplaceLambdaWithMethodReference changes () -> field.getValue() to field::getValue, with runtime NPE if field is only initialized later.

Anything in particular you'd like reviewers to focus on?

This is currently too broad and breaking three original test cases, but I'm not quite sure how to narrow it down further. From the perspective of do-no-harm we might disable those test cases though, as the addition here is safer.

@timtebeek timtebeek added the bug Something isn't working label Feb 9, 2024
@timtebeek timtebeek self-assigned this Feb 9, 2024
@timtebeek
Copy link
Member Author

Saving others a click with these expected failures:
https://ge.openrewrite.org/s/6puggbyyvem5u/tests/overview?outcome=FAILED

org.openrewrite.staticanalysis.ReplaceLambdaWithMethodReferenceTest
FAILED 14.271s 0.117s 14.271s
voidMethodReference()
FAILED 0.308s
functionReference()
FAILED 0.281s
nonStaticMethods()
FAILED 0.276s

Copy link
Contributor

@knutwannheden knutwannheden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me. It should be safe if the field has the final modifier (also available via type attribution). Using that we should be able to make this a little bit less restrictive.

@timtebeek timtebeek marked this pull request as ready for review February 9, 2024 19:07
@timtebeek
Copy link
Member Author

Thanks! That extra check indeed meant I only had to change one test that only seemed to use fields by chance.

@timtebeek timtebeek merged commit 59bf480 into main Feb 9, 2024
@timtebeek timtebeek deleted the do-not-replaceLambdaWithMethodReference-for-class-fields branch February 9, 2024 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants