Skip to content

[Java] Throw IllegalArgumentException for invalid field access expressions - #41993

Open
raman118 wants to merge 1 commit into
apache:masterfrom
raman118:fix-field-access-parser-npe
Open

raman118 wants to merge 1 commit into
apache:masterfrom
raman118:fix-field-access-parser-npe

Conversation

@raman118

@raman118 raman118 commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #21284

FieldAccessDescriptorParser kept ANTLR's default error listeners. Those only print syntax errors to stderr and let parsing continue, so the visitor later hit missing nodes and failed with a NullPointerException. The exception didn't mention the bad expression.

This change replaces the default listeners on the lexer and the parser with one that throws:

java.lang.IllegalArgumentException: Invalid field access expression 'a.' at position 2: mismatched input '<EOF>' expecting ...

This applies to every caller of the parser, for example FieldAccessDescriptor.withFieldNames, withFieldNamesAs and Select.fieldNames.

Tests: new cases in FieldAccessDescriptorParserTest cover an invalid token, an incomplete expression and withFieldNamesAs. ./gradlew :sdks:java:core:test --tests 'org.apache.beam.sdk.schemas.FieldAccessDescriptor*' passes (24 tests), and spotless is clean.


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

🤖 Generated with Claude Code

…sions

FieldAccessDescriptorParser used ANTLR's default error listeners, which
only print syntax errors to stderr and let parsing continue. The visitor
then hit missing nodes and failed with a NullPointerException that gave
no hint about the bad expression.

Replace the default listeners on the lexer and parser with one that
throws an IllegalArgumentException naming the expression, the position
and the parser message.

Fixes apache#21284

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @shunping added as fallback since no labels match configuration
Backup reviewer: kennknowles (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FieldAccessDescriptorParser failures throw NPE

1 participant