usethesource / rascal

The implementation of the Rascal meta-programming language (including interpreter, type checker, parser generator, compiler and JVM based run-time system)
http://www.rascal-mpl.org
Other
400 stars 77 forks source link

strange NPE in java-air #1901

Closed jurgenvinju closed 8 months ago

jurgenvinju commented 8 months ago

This report is via via @BastiaanHeeren.

Using JDK 11. and extracting M3 and an AST for this file:

public class Error extends MenuBar {

    protected static final String VIEW = "View";

}
rascal>error();
Got NPE for node VIEW="View"
        org.rascalmpl.library.lang.java.m3.internal.ASTConverter.resolveType(ASTConverter.java:154)
ok
jurgenvinju commented 8 months ago
rascal>public void error() {
>>>>>>>   set[Declaration] decls = createAstsFromFiles({|home:///Error.java|}, false);
>>>>>>>   visit(decls) {  
>>>>>>>      case \if(cond, _): {
>>>>>>>         println("condition at <cond.src>");
>>>>>>>      }
>>>>>>>   }
>>>>>>>}
void (): function(|prompt:///|(0,208,<1,0>,<8,1>))
rascal>error()
Got NPE for node VIEW="View"
        org.rascalmpl.library.lang.java.m3.internal.ASTConverter.resolveType(ASTConverter.java:154)
ok
jurgenvinju commented 8 months ago
rascal>public void error2() {
>>>>>>>   set[Declaration] decls = createAstsFromFiles({|home:///Error.java|}, false);
>>>>>>>}
void (): function(|prompt:///|(0,104,<1,0>,<3,1>))
rascal>error2()
Got NPE for node VIEW="View"
        org.rascalmpl.library.lang.java.m3.internal.ASTConverter.resolveType(ASTConverter.java:154)
ok
rascal>public void error3() {
>>>>>>>   set[Declaration] decls = createAstsFromFiles({|home:///Error.java|}, true);
>>>>>>>}
void (): function(|prompt:///|(0,103,<1,0>,<3,1>))
rascal>error3()
ok
jurgenvinju commented 8 months ago

Thanks for reporting this @BastiaanHeeren; the code was trying to resolve a type for a field anyway while type resolution was turned off. This explains the NPE.