Closed shivanisky closed 3 months ago
Thanks for logging the issue here! I could even transfer this to rewrite-static-analysis if you agree; that way it's more broadly applicable. Let me know!
Thanks for logging the issue here! I could even transfer this to rewrite-static-analysis if you agree; that way it's more broadly applicable. Let me know!
Sure thing, that makes sense. You would know what's best!
Turns out we already have an UnnecessaryThrows recipe; we can move this back to rewrite-testing frameworks for inclusion there. :)
When running the junit 4 to 5 migration recipe, in the assertThrows case checked exceptions are not removed. This results in unused exceptions left in the method signature which are handled by the assertThrows case, and results in intellij warnings.
Any additional context
@timtebeek has mentioned that this could be fixed in a similar way to the issue where unecessary catch blocks exist to catch exceptions not thrown by try blocks, and could be a separate recipe to fix all unecessary checked exceptions: https://docs.openrewrite.org/recipes/staticanalysis/unnecessarycatch
Here is the code to detect unecessary exceptions: https://github.com/openrewrite/rewrite-static-analysis/blob/6d04813574c6b02c8bf7d6e2f66b2bdaa881854c/src/main/java/org/openrewrite/staticanalysis/UnnecessaryCatch.java#L79-L94