This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 252630 - NullPointerException when parsing some error after the update of jython-parser to 2.7.
Summary: NullPointerException when parsing some error after the update of jython-parse...
Status: VERIFIED FIXED
Alias: None
Product: python
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.1
Hardware: PC Linux
: P3 normal (vote)
Assignee: juniel_katarn
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-27 20:31 UTC by Jenselme
Modified: 2015-11-27 19:04 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
NullPointerException stacktrace (3.34 KB, text/plain)
2015-05-27 20:44 UTC, Jenselme
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jenselme 2015-05-27 20:31:35 UTC

    
Comment 1 Jenselme 2015-05-27 20:37:09 UTC
After the update of jython-parser, I encounter an error when parsing some code.

Step to reproduce:
1. Update to have this patch: http://hg.netbeans.org/main/contrib/rev/7268510f9338
2. Start typing a list comprehension, eg: a = [c for c in "hello"]
3. The bug should appear once you typed [c for c i]

Netbeans version:
Product Version: NetBeans IDE Dev (Build 20150527-e8112fc19595)
Java: 1.7.0_79; OpenJDK 64-Bit Server VM 24.79-b02
Runtime: OpenJDK Runtime Environment 1.7.0_79-b14
System: Linux version 3.16.7-21-desktop running on amd64; UTF-8; fr_FR (nb)
Comment 2 Jenselme 2015-05-27 20:44:35 UTC
Created attachment 153909 [details]
NullPointerException stacktrace
Comment 3 Jenselme 2015-07-09 09:50:37 UTC
I think I was able to figure out what the problem was. The exception is raised in PythonParser#reportError at line 308 when calling super.reportError. In the parent class, reportError just calls BaseRecognizer#reportError (The code is here: https://github.com/antlr/antlr3/blob/master/runtime/Java/src/main/java/org/antlr/runtime/BaseRecognizer.java#L176). It crashes at line 251 (https://github.com/antlr/antlr3/blob/master/runtime/Java/src/main/java/org/antlr/runtime/BaseRecognizer.java#L251) when trying to access to the tokenNames array.

It needs an array of token names to work properly. By default, BaseRecognizer#getTokenNames returns null (See https://github.com/antlr/antlr3/blob/master/runtime/Java/src/main/java/org/antlr/runtime/BaseRecognizer.java#L758). We create a new BaseRecognizer to avoid a StackOverflow with the default getTokenNames method. Hence the NullPointerException.

My patch simply overrides getTokenNames to return the array of token names from the previous BaseRecognizer. Since the BaseRecognizer#reportError relies on its parameter to work (See: https://github.com/antlr/antlr3/blob/master/runtime/Java/src/main/java/org/antlr/runtime/BaseRecognizer.java#L17), I think we can assume that my patch does the job correctly.

The patch is available here: https://bitbucket.org/Jenselme/nb-contrib/commits/branch/bz252630-nullptrexception-after-update-jython_parser-2.7 Review appreciated.
Comment 4 Jenselme 2015-07-31 16:32:27 UTC
Fixed in http://hg.netbeans.org/main/contrib/rev/0bf82b105206