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

CatchClauseOnlyRethrows should not remove empty catch if the exception then gets caught by another catch block #4235

Closed
knutwannheden opened this issue Jun 7, 2024 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@knutwannheden
Copy link
Contributor

Problem

As can be seen in the example, a catch block is removed that was added for a specific subtype of an exception to just have it rethrown. Now, that the catch block is removed, the exception will get handled by a different catch block, which is the wrong thing to do.

Expected behavior

In this case the recipe should not remove the catch block. Checking for any following catch blocks is the easy fix here.

Example diff

From: spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArraySingleTerminatorSerializer.java

 			}
return copyToSizedArray(buffer, n);
}
-		catch (SoftEndOfStreamException e) { // NOSONAR catch and throw
-			throw e; // it's an IO exception and we don't want an event for this
-		}
catch (IOException | RuntimeException ex) {
publishEvent(ex, buffer, n);
throw ex;

Recipes in example diff:

  • org.openrewrite.staticanalysis.CatchClauseOnlyRethrows

References:

  • View original result
  • Recipe ID: org.openrewrite.staticanalysis.CatchClauseOnlyRethrows
  • Recipe Name: Catch clause should do more than just rethrow
  • Repository: spring-projects/spring-integration/main
  • Created at Fri Jun 07 2024 16:24:12 GMT+0200 (Central European Summer Time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
Archived in project
Development

No branches or pull requests

1 participant