Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed null pointer exception for JS target #1736

Merged
merged 1 commit into from
Mar 9, 2017
Merged

Conversation

harrytallbelt
Copy link

@harrytallbelt harrytallbelt commented Mar 8, 2017

For JavaScript target, getToken and getChild methods in ParserRuleContext.js did not check if this.children is null as code for Java target did. I added the two if statements Java implementation has in these methods.

For an example of where the problem arises, consider the rule

program : /* nothing */ | statements ;

If the input is empty (i.e. statements is not matched), the visitor's method

ProgramBaseVisitor.prototype.visitProgram = function(ctx) {
  return { statements: ctx.statements() ? this.visit(ctx.statements()) : [] }
}

fails on the ctx.statements() call, because of an attempt to access this.children.length in ParserRuleContext.js's getChild method.

Meanwhile, the Java implementation of the same thing has no problem calling ctx.statements().

@parrt
Copy link
Member

parrt commented Mar 8, 2017

@ericvergnaud blessed?

@ericvergnaud
Copy link
Contributor

ericvergnaud commented Mar 9, 2017 via email

@parrt parrt added this to the 4.7 milestone Mar 9, 2017
@parrt parrt merged commit 892a749 into antlr:master Mar 9, 2017
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.

3 participants