Skip to content

Conversation

knutwannheden
Copy link
Contributor

@knutwannheden
Copy link
Contributor Author

@timtebeek Is this the right place to add the recipe?

@knutwannheden
Copy link
Contributor Author

@timtebeek Also, I don't know if this can be integrated before a new release has been made. Is the CI using the released version or SNAPSHOT builds?

@timtebeek
Copy link
Member

I'm not sure of your intentions with the System.out.println in 507f67d;
but I've approved the run just this once; if that's what hacks us well done. ;)

@knutwannheden
Copy link
Contributor Author

I'm not sure of your intentions with the System.out.println in 507f67d;
but I've approved the run just this once; if that's what hacks us well done. ;)

I just added a test to make sure that the new recipe is also being used. If the System.out.println() call in the test (which of course won't get executed) bothers you, we can of course change it 😄

@knutwannheden
Copy link
Contributor Author

Looks like the recipe wasn't applied properly. Makes me wonder why the test didn't fail before I modified it. Shouldn't it complain if it can't find the recipe? I could debug that.

@timtebeek
Copy link
Member

It should; surprised it didn't. Thanks for troubleshooting either way; it's good to uncover these cross-repository issues this way. Likely wouldn't have registered if it was indeed in the same repository.

@knutwannheden
Copy link
Contributor Author

It should; surprised it didn't. Thanks for troubleshooting either way; it's good to uncover these cross-repository issues this way. Likely wouldn't have registered if it was indeed in the same repository.

Actually, my test is wrong. I will fix it.

@knutwannheden knutwannheden force-pushed the java17-instanceof-pattern branch from 507f67d to 6353b41 Compare January 31, 2023 14:16
@knutwannheden
Copy link
Contributor Author

Actually, my test is wrong. I will fix it.

The problem with the test was that the instanceof and type cast expressions were method invocations, which we can't know if they have side effects. So theoretically it could be important that the method gets called twice. That is why the recipe doesn't get applied and I had to extract the expression into a variable first. I had myself forgotten about this safety guard.

I will add an issue for support of IntelliJ's @Contract annotation, which could be used for more precise side-effects calculations. Why Map#get(Object) isn't annotated as @Contract(pure=true) (see https://github.com/JetBrains/intellij-community/blob/master/java/jdkAnnotations/java/util/annotations.xml#L3249-L3254) I am unsure about, so that wouldn't have made a difference in my example.

@sambsnyd sambsnyd merged commit 316f660 into openrewrite:main Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants