Skip to content

Parser fails when it encounters a variable named _ #240

Open
@donalmurtagh

Description

Describe the bug
In JDK v22, a feature was added to the Java language that allows unused variables to be named _. When the java parser encounters such a variable, it fails

To Reproduce
Run the annotator under JDK v22 on a codebase that contains an unused variable named _. The following sections show the relevant dependency versions, configuration, etc.

build.gradle

Relevant sections of the build file are

plugins {
    id "net.ltgt.errorprone" version "4.0.1"
}

dependencies {
    implementation "org.jspecify:jspecify:1.0.0"
    annotationProcessor 'edu.ucr.cs.riple.annotator:annotator-scanner:1.3.14'
    annotationProcessor "com.uber.nullaway:nullaway:0.11.1"
    errorprone "com.google.errorprone:error_prone_core:2.30.0"
    errorproneJavac "com.google.errorprone:javac:9+181-r4173-1"
}

tasks.withType(JavaCompile).configureEach {
    options.errorprone {
        check("NullAway", CheckSeverity.ERROR)
        check("AnnotatorScanner", CheckSeverity.ERROR)
        option("NullAway:AnnotatedPackages", "com.myapp")
        option("NullAway:SerializeFixMetadata", "true")
        option("NullAway:FixSerializationConfigPath", "/Users/donal/tmp/annotator-output/nullaway.xml")
        option("AnnotatorScanner:ConfigPath", "/Users/donal/tmp/annotator-output/scanner.xml")
    }

    options.compilerArgs << "-Xmaxerrs"<< "100000"
    options.compilerArgs << "-Xmaxwarns" << "100000"
}

paths.tsv

A tab character separates the two paths.

/Users/donal/tmp/annotator-output/nullaway.xml	/Users/donal/tmp/annotator-output/scanner.xml

Annotator Command

java -jar ~/tmp/annotator-core-1.3.14.jar -d ~/tmp/annotator-output -i jakarta.annotation.PostConstruct -bc "cd ~/workspace/my-app && ./gradlew build -x test" -cn NULLAWAY -cp ~/tmp/paths.tsv -n org.jspecify.annotations.Nullable

Expected behavior
Annotator should run successfully

Stack trace

Exception in thread "main" com.github.javaparser.ParseProblemException: (line 51,col 38) '_' is a reserved keyword.

        at com.github.javaparser.JavaParserAdapter.handleResult(JavaParserAdapter.java:83)
        at com.github.javaparser.JavaParserAdapter.parse(JavaParserAdapter.java:99)
        at com.github.javaparser.StaticJavaParser.parse(StaticJavaParser.java:173)
        at edu.ucr.cs.riple.injector.Injector.parse(Injector.java:173)
        at edu.ucr.cs.riple.core.registries.field.FieldRegistry$1.build(FieldRegistry.java:115)
        at edu.ucr.cs.riple.core.registries.field.FieldRegistry$1.build(FieldRegistry.java:97)
        at edu.ucr.cs.riple.core.registries.Registry.populateContent(Registry.java:122)
        at edu.ucr.cs.riple.core.registries.Registry.lambda$new$0(Registry.java:91)
        at java.base/java.lang.Iterable.forEach(Iterable.java:75)
        at edu.ucr.cs.riple.core.registries.Registry.<init>(Registry.java:88)
        at edu.ucr.cs.riple.core.registries.field.FieldRegistry.<init>(FieldRegistry.java:82)
        at edu.ucr.cs.riple.core.module.ModuleInfo.<init>(ModuleInfo.java:91)
        at edu.ucr.cs.riple.core.module.ModuleInfo.<init>(ModuleInfo.java:73)
        at edu.ucr.cs.riple.core.Context.<init>(Context.java:78)
        at edu.ucr.cs.riple.core.Annotator.<init>(Annotator.java:63)
        at edu.ucr.cs.riple.core.Main.main(Main.java:45)

OS (please complete the following information):

  • OS: MacOS X
  • Version: openjdk version "22.0.1" 2024-04-16
  • Annotator Version: 1.3.14 (latest)

Metadata

Labels

javaparserRelevant to Javaparser projectlong runA TODO for long run

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions