Skip to content

Fix NullPointerException in CucumberJvmHandler and FilesLocator#53

Open
micheleh wants to merge 1 commit intomasterfrom
fix/null-pointer-handler-and-locator
Open

Fix NullPointerException in CucumberJvmHandler and FilesLocator#53
micheleh wants to merge 1 commit intomasterfrom
fix/null-pointer-handler-and-locator

Conversation

@micheleh
Copy link
Copy Markdown
Collaborator

@micheleh micheleh commented Apr 4, 2026

Summary

  • Added null guard in CucumberJvmHandler line 96 before calling startsWith() on the result of findLastNonEmptyLine(), which returns null for empty/whitespace-only error messages
  • Added null check for File.listFiles() in FilesLocator, throwing a descriptive RuntimeException instead of NPE when a directory cannot be read

Context

Both issues have existed since the initial commit (c71ed1f, 2021-11-15). The CucumberJvmHandler caller was modified 3 times by 3 different authors — none added a null check. A failure element with empty text content (e.g., "\n\n\n") would crash the entire conversion process.

Verification

  • Empty and whitespace-only error messages no longer cause NPE in CucumberJvmHandler
  • Unreadable directories produce a descriptive error instead of NPE in FilesLocator
  • Full test suite passes (42 tests, 0 failures)

Add null check for findLastNonEmptyLine() return value before
dereferencing in CucumberJvmHandler.setElement(). Guard against
File.listFiles() returning null in FilesLocator with a descriptive
error message instead of NPE.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@micheleh micheleh requested a review from nissimshitrit April 4, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant