Skip to content

Conversation

@Gautam-aman
Copy link

@Gautam-aman Gautam-aman commented Jan 4, 2026

Problem

NestedEnumsAreNotStatic assumed all class declarations have a non-null body,
leading to a NullPointerException when analyzing certain nested enum constructs.

Solution

  • Added a defensive guard against null class bodies
  • Added a regression test to ensure the recipe no longer throws

Testing

  • New unit test added
  • All existing tests pass

Signed-off-by: Aman Gautam <amangautam2128@gmail.com>
Comment on lines +81 to +93
@Test
void issue796_nullClassBodyDoesNotThrow() {
rewriteRun(
//language=java
java(
"""
class Outer {
enum Inner {}
}
"""
)
);
}
Copy link
Member

Choose a reason for hiding this comment

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

This test also passes on main without any recipe changes, so I don't think it accurately reflects the issue we're intending to fix here. I also don't see the outer or inner class body parsed as null, so I'm not sure the conditionals added here would do anything in practice. What lead you to these changes?

Copy link
Member

Choose a reason for hiding this comment

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

Also since the nested inner enum isn't static, we wouldn't expect any action from the recipe either.

@timtebeek timtebeek marked this pull request as draft January 5, 2026 10:57
@timtebeek timtebeek closed this in 736160d Jan 5, 2026
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Jan 5, 2026
@timtebeek
Copy link
Member

Seeing your changes and the original recipe implementation here I've gone ahead and removed some duplicate logic and traversal: 736160d
Given my comments above I still don't feel we've accurately replicated or fixed #796; perhaps a combination of recipes is still involved here.

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

NullPointerException (NPE) in NestedEnumsAreNotStatic

2 participants