antlr / antlr/antlr4

NullPointer in DefaultErrorStrategy when Using CommonToken with EMPTY_SOURCE

Open
#951 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

comp:runtime type:suggestion
Dominant language
Java
Stars
19k
Forks
3.5k
PR merge metrics
No merged PRs in 30d

Description

Line 589 in DefaultErrorStrategy gives a null pointer when I'm feeding a customly new'ed CommonToken that has the default source of EMPTY_SOURCE

new Pair<TokenSource, CharStream>(current.getTokenSource(), current.getTokenSource().getInputStream())

When getTokenSource returns null, an NPE happens here. The workaround is to make sure a CommonToken has a valid tokenSource...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in DefaultErrorStrategy at line 589 and trace the CommonToken path when its source is EMPTY_SOURCE. Reproduce the failure with a newly constructed CommonToken, then compare it with a token that has a valid tokenSource. Done means this scenario no longer raises a NullPointerException and the relevant Java runtime tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.