Skip to content

RemoveRedundantFeatureFlags should retain new ObjectMapper() at start of chain#87

Merged
timtebeek merged 3 commits intoopenrewrite:mainfrom
mcclellanmj:fix-fluent-remove-redundant-feature-flags
Feb 25, 2026
Merged

RemoveRedundantFeatureFlags should retain new ObjectMapper() at start of chain#87
timtebeek merged 3 commits intoopenrewrite:mainfrom
mcclellanmj:fix-fluent-remove-redundant-feature-flags

Conversation

@mcclellanmj
Copy link
Contributor

What's changed?

When configure/enable/disable is chained on new ObjectMapper(), the select is J.NewClass not J.MethodInvocation. Treat both as chain and return the select so the expression becomes 'new ObjectMapper()' instead of being removed (which left 'return;').

What's your motivation?

Fixes an issue I discovered while running rewrite on my projects

Anything in particular you'd like reviewers to focus on?

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

I did not see any potential workaround to this aside from manually fixing the places it incorrectly removed code.

Any additional context

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

mcclellanmj and others added 2 commits February 25, 2026 11:32
When configure/enable/disable is chained on new ObjectMapper(), the
select is J.NewClass not J.MethodInvocation. Treat both as chain
and return the select so the expression becomes 'new ObjectMapper()'
instead of being removed (which left 'return;').

Also renames test to removeConfigureChainedOnNewObjectMapper.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the immediate fix!

@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Feb 25, 2026
@timtebeek timtebeek added the bug Something isn't working label Feb 25, 2026
@mcclellanmj
Copy link
Contributor Author

Looked like my autoformat broke the test and I didn't notice it. Fixed that.

@timtebeek timtebeek changed the title Fix RemoveRedundantFeatureFlags for fluent constructor chains RemoveRedundantFeatureFlags should retain new ObjectMapper() at start of chain Feb 25, 2026
@timtebeek timtebeek merged commit 081c143 into openrewrite:main Feb 25, 2026
1 check passed
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Feb 25, 2026
@timtebeek
Copy link
Member

Perfect, thanks a lot for the quick rework. Should go out with the next release in ~2 weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants