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

Have DirectReturn check consider finally blocks #568

Merged
merged 3 commits into from
Apr 14, 2023

Conversation

Stephan202
Copy link
Member

@Stephan202 Stephan202 commented Apr 6, 2023

Resolves an issue reported by @francisco-f-silva.

Suggested commit message:

Have `DirectReturn` check consider `finally` blocks (#568)

@Stephan202 Stephan202 added this to the 0.10.0 milestone Apr 6, 2023
@Stephan202 Stephan202 requested a review from rickie April 6, 2023 19:51
* <p>Inlining an expression generally does not change its return type, but in rare cases the
* operation may have a functional impact. The sole case considered here is the inlining of a
* Mockito mock or spy construction without an explicit type. In such a case the type created
* depends on context, such as the method's return type.
*/
private static boolean canInlineToReturnStatement(
Copy link
Member Author

Choose a reason for hiding this comment

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

Should now find a better name for this method. Suggestions welcome.

Copy link
Member

Choose a reason for hiding this comment

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

We could add Tree or something, but that doesn't add a lot.

In EP they use the term "inlineable". We could do something with that. I cannot think of many suggestions as "inline" is the best verb here IMO.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, my concern here is more that canInline is actually too strong, since now this method only tests are required, but not sufficient set of conditions to be met. I guess we can just merge as-is.

@github-actions
Copy link

github-actions bot commented Apr 6, 2023

Looks good. All 18 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.bugpatterns.DirectReturn$1 0 7
🎉tech.picnic.errorprone.bugpatterns.DirectReturn 0 11

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@Stephan202 Stephan202 force-pushed the sschroevers/direct-return-finally-blocks branch from d17ea37 to 0231333 Compare April 7, 2023 05:12
@github-actions
Copy link

github-actions bot commented Apr 7, 2023

Looks good. All 20 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.bugpatterns.DirectReturn$1 0 7
🎉tech.picnic.errorprone.bugpatterns.DirectReturn 0 13

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

1 similar comment
@github-actions
Copy link

github-actions bot commented Apr 7, 2023

Looks good. All 20 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.bugpatterns.DirectReturn$1 0 7
🎉tech.picnic.errorprone.bugpatterns.DirectReturn 0 13

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Apr 8, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@rickie rickie requested a review from oxkitsune April 13, 2023 10:35
Copy link
Contributor

@oxkitsune oxkitsune left a comment

Choose a reason for hiding this comment

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

A return statement is allowed in a finally block 😨?

@Stephan202
Copy link
Member Author

Not necessarily recommended 😅

@rickie rickie force-pushed the sschroevers/direct-return-finally-blocks branch from 0231333 to d513989 Compare April 14, 2023 06:49
@github-actions
Copy link

Looks good. All 20 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.bugpatterns.DirectReturn$1 0 7
🎉tech.picnic.errorprone.bugpatterns.DirectReturn 0 13

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member

@rickie rickie left a comment

Choose a reason for hiding this comment

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

Thanks for fixing the issue so fast after it popped up :).

* executed <em>after</em> control flow returns from the {@link VisitorState#getPath() current
* location}.
*/
private static boolean isSymbolReferencedInAssociatedFinallyBlock(
Copy link
Member

Choose a reason for hiding this comment

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

For this method name we are not using identifierSymbol while below we are 🤔. Should we update this method name to also mentions identifier as that is what it does.

* <p>Inlining an expression generally does not change its return type, but in rare cases the
* operation may have a functional impact. The sole case considered here is the inlining of a
* Mockito mock or spy construction without an explicit type. In such a case the type created
* depends on context, such as the method's return type.
*/
private static boolean canInlineToReturnStatement(
Copy link
Member

Choose a reason for hiding this comment

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

We could add Tree or something, but that doesn't add a lot.

In EP they use the term "inlineable". We could do something with that. I cannot think of many suggestions as "inline" is the best verb here IMO.

Copy link
Member Author

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

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

Added a commit. Tnx for the review!

* <p>Inlining an expression generally does not change its return type, but in rare cases the
* operation may have a functional impact. The sole case considered here is the inlining of a
* Mockito mock or spy construction without an explicit type. In such a case the type created
* depends on context, such as the method's return type.
*/
private static boolean canInlineToReturnStatement(
Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, my concern here is more that canInline is actually too strong, since now this method only tests are required, but not sufficient set of conditions to be met. I guess we can just merge as-is.

@github-actions
Copy link

Looks good. All 20 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.bugpatterns.DirectReturn$1 0 7
🎉tech.picnic.errorprone.bugpatterns.DirectReturn 0 13

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@rickie rickie merged commit 9b54c73 into master Apr 14, 2023
@rickie rickie deleted the sschroevers/direct-return-finally-blocks branch April 14, 2023 10:56
@rickie rickie added bug Something isn't working and removed improvement labels May 5, 2023
@rickie
Copy link
Member

rickie commented May 5, 2023

Changed this to a bug as it was reported as such :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

3 participants