Skip to content

Conversation

@timtebeek
Copy link
Member

Summary

  • Adds a new recipe SimplifyJacksonExceptionCatch that simplifies multi-catch clauses where Jackson exceptions are caught alongside RuntimeException
  • In Jackson 3, JacksonException and its subtypes extend RuntimeException, making it redundant to catch both
  • Handles all Jackson 3 exception types: JacksonException, StreamReadException, StreamWriteException, UnexpectedEndOfInputException, and DatabindException
  • Removes unnecessary imports for the removed exception types

Example

// Before
try {
    mapper.readValue(json, MyClass.class);
} catch (JacksonException | RuntimeException e) {
    e.printStackTrace();
}

// After  
try {
    mapper.readValue(json, MyClass.class);
} catch (RuntimeException e) {
    e.printStackTrace();
}

Test plan

  • Added comprehensive tests covering basic simplification, subtype handling, multiple exceptions, preserving other types, and no-change scenarios
  • All tests pass locally

🤖 Generated with Claude Code

In Jackson 3, JacksonException and its subtypes extend RuntimeException.
This recipe simplifies multi-catch clauses by removing Jackson exception
types when RuntimeException is also caught, since catching both is
redundant.

For example:
  catch (JacksonException | RuntimeException e)
becomes:
  catch (RuntimeException e)

Handles all Jackson 3 exception types including JacksonException,
StreamReadException, StreamWriteException, UnexpectedEndOfInputException,
and DatabindException.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@timtebeek timtebeek requested a review from MBoegers December 12, 2025 14:39
@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite Dec 12, 2025
@timtebeek timtebeek marked this pull request as ready for review December 12, 2025 14:39
@timtebeek timtebeek merged commit 95772cd into main Dec 12, 2025
2 checks passed
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Dec 12, 2025
@timtebeek timtebeek deleted the simplify-jackson-exception-catch branch December 12, 2025 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants