Skip to content

Fix NPE in NestedEnumsAreNotStatic when class body is null - #957

Open
devsuyash-Hq wants to merge 1 commit into
openrewrite:mainfrom
devsuyash-Hq:fix-796-npe-nested-enums
Open

Fix NPE in NestedEnumsAreNotStatic when class body is null#957
devsuyash-Hq wants to merge 1 commit into
openrewrite:mainfrom
devsuyash-Hq:fix-796-npe-nested-enums

Conversation

@devsuyash-Hq

@devsuyash-Hq devsuyash-Hq commented Aug 1, 2026

Copy link
Copy Markdown

What's changed?

Added a null check for ClassDeclaration.getBody() in NestedEnumsAreNotStatic's shouldRemoveStaticModifierFromClass method.

What's your motivation?

Previously, when a class declaration's body was null, the recipe would still call maybeAutoFormat, causing a NullPointerException deep in SpacesVisitor.visitClassDeclaration (getBody().getPrefix() on a null body).

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

This is a defensive fix based on the reported stack trace rather than a literal reproduction, since the null body appears to stem from a parser edge case that's difficult to construct directly in a test. Ran the full existing NestedEnumsAreNotStaticTest suite — all tests pass.

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Could alternatively guard inside maybeAutoFormat or SpacesVisitor itself, but scoping the fix to this recipe felt safer and more targeted to the reported issue.

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

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

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

NullPointerException (NPE) in NestedEnumsAreNotStatic

1 participant