Skip to content

Fix NullPointerException when visitListItem encounters a non-paragraph first child.#1411

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_945788396
Jul 10, 2026
Merged

Fix NullPointerException when visitListItem encounters a non-paragraph first child.#1411
copybara-service[bot] merged 1 commit into
masterfrom
test_945788396

Conversation

@copybara-service

Copy link
Copy Markdown

Fix NullPointerException when visitListItem encounters a non-paragraph first child.

visitListItem in MarkdownPositions previously used a pattern-matching switch on listItem.getFirstChild(). If a Markdown ListItem starts with a non-paragraph child (such as when an empty or unfinished bullet item /// - has null as its first child), the switch statement throws a NullPointerException because it does not explicitly handle null.

This change replaces the switch with if (listItem.getFirstChild() instanceof Paragraph paragraph) to safely return false on null or non-Paragraph children without throwing an exception. It also updates LIST_ITEM_START_PATTERN to allow list markers without trailing whitespace at the end of the input ($).

Tested:
Added markdownEmptyListItem in JavadocFormattingTest.java and ran blaze test //third_party/java_src/google_java_format/....

@copybara-service copybara-service Bot force-pushed the test_945788396 branch 3 times, most recently from 747bf1b to 4586194 Compare July 10, 2026 18:50
…graph first child.

`visitListItem` in `MarkdownPositions` previously used a pattern-matching `switch` on `listItem.getFirstChild()`. If a Markdown `ListItem` starts with a non-paragraph child (such as when an empty or unfinished bullet item `/// -` has `null` as its first child), the `switch` statement throws a `NullPointerException` because it does not explicitly handle `null`.

This change replaces the `switch` with `if (listItem.getFirstChild() instanceof Paragraph paragraph)` to safely return `false` on `null` or non-`Paragraph` children without throwing an exception. It also updates `LIST_ITEM_START_PATTERN` to allow list markers without trailing whitespace at the end of the input (`$`).

Tested:
Added `markdownEmptyListItem` in `JavadocFormattingTest.java` and ran `blaze test //third_party/java_src/google_java_format/...`.
PiperOrigin-RevId: 945823851
@copybara-service copybara-service Bot merged commit adf9252 into master Jul 10, 2026
@copybara-service copybara-service Bot deleted the test_945788396 branch July 10, 2026 18:57
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