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

Parser fails when it encounters a variable named _ #240

Open
donalmurtagh opened this issue Aug 14, 2024 · 2 comments
Open

Parser fails when it encounters a variable named _ #240

donalmurtagh opened this issue Aug 14, 2024 · 2 comments
Assignees
Labels
javaparser Relevant to Javaparser project long run A TODO for long run

Comments

@donalmurtagh
Copy link

donalmurtagh commented Aug 14, 2024

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)
@donalmurtagh
Copy link
Author

donalmurtagh commented Aug 14, 2024

I guess there's not much the annotator can do about this until the java parser supports unnamed variables

@nimakarimipour nimakarimipour added the long run A TODO for long run label Oct 30, 2024
@nimakarimipour nimakarimipour self-assigned this Oct 30, 2024
@nimakarimipour
Copy link
Member

nimakarimipour commented Oct 30, 2024

@donalmurtagh Thanks for reporting the issue! I wanted to let you know that I’m actively monitoring for a new javaparser release. Once a release supporting Java 22 features is available, I’ll update the Annotator accordingly and inform you.

@nimakarimipour nimakarimipour added the javaparser Relevant to Javaparser project label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javaparser Relevant to Javaparser project long run A TODO for long run
Projects
None yet
Development

No branches or pull requests

2 participants