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

com.github.javaparser.ParseProblemException #229

Open
boris-petrov opened this issue Apr 4, 2024 · 3 comments
Open

com.github.javaparser.ParseProblemException #229

boris-petrov opened this issue Apr 4, 2024 · 3 comments
Labels
long run A TODO for long run

Comments

@boris-petrov
Copy link

Describe the bug
That's probably not an issue with this project but rather with javaparser but I promised to write here @nimakarimipour. 😄

I get the following exception:

Exception in thread "main" com.github.javaparser.ParseProblemException: (line 607,col 49) Parse error. Found "(", expected one of  "!=" "%=" "&" "&&" "&=" "*=" "+=" "-=" "->" "/=" "::" ";" "<<=" "=" "==" ">>=" ">>>=" "?" "^" "^=" "|" "|=" "||"
Problem stacktrace :
  com.github.javaparser.GeneratedJavaParser.generateParseException(GeneratedJavaParser.java:14041)
  com.github.javaparser.GeneratedJavaParser.jj_consume_token(GeneratedJavaParser.java:13886)
  com.github.javaparser.GeneratedJavaParser.ReturnStatement(GeneratedJavaParser.java:7119)
  com.github.javaparser.GeneratedJavaParser.Statement(GeneratedJavaParser.java:5711)
  com.github.javaparser.GeneratedJavaParser.BlockStatement(GeneratedJavaParser.java:5933)
  com.github.javaparser.GeneratedJavaParser.Statements(GeneratedJavaParser.java:2795)
  com.github.javaparser.GeneratedJavaParser.Block(GeneratedJavaParser.java:5810)
  com.github.javaparser.GeneratedJavaParser.MethodDeclaration(GeneratedJavaParser.java:2188)
  com.github.javaparser.GeneratedJavaParser.RecordBodyDeclaration(GeneratedJavaParser.java:1560)
  com.github.javaparser.GeneratedJavaParser.RecordBody(GeneratedJavaParser.java:1410)
  com.github.javaparser.GeneratedJavaParser.RecordDeclaration(GeneratedJavaParser.java:606)
  com.github.javaparser.GeneratedJavaParser.RecordBodyDeclaration(GeneratedJavaParser.java:1521)
  com.github.javaparser.GeneratedJavaParser.RecordBody(GeneratedJavaParser.java:1410)
  com.github.javaparser.GeneratedJavaParser.RecordDeclaration(GeneratedJavaParser.java:606)
  com.github.javaparser.GeneratedJavaParser.ClassOrInterfaceBodyDeclaration(GeneratedJavaParser.java:1746)
  com.github.javaparser.GeneratedJavaParser.ClassOrInterfaceBody(GeneratedJavaParser.java:1281)
  com.github.javaparser.GeneratedJavaParser.ClassOrInterfaceDeclaration(GeneratedJavaParser.java:538)
  com.github.javaparser.GeneratedJavaParser.CompilationUnit(GeneratedJavaParser.java:156)
  com.github.javaparser.JavaParser.parse(JavaParser.java:125)
  com.github.javaparser.JavaParser.parse(JavaParser.java:231)
  com.github.javaparser.JavaParserAdapter.parse(JavaParserAdapter.java:99)
  com.github.javaparser.StaticJavaParser.parse(StaticJavaParser.java:173)
  edu.ucr.cs.riple.injector.Injector.parse(Injector.java:163)
  edu.ucr.cs.riple.core.registries.field.FieldRegistry.lambda$getBuilder$4(FieldRegistry.java:100)
  edu.ucr.cs.riple.core.registries.Registry.populateContent(Registry.java:117)
  edu.ucr.cs.riple.core.registries.Registry.lambda$new$0(Registry.java:86)
  java.base/java.lang.Iterable.forEach(Iterable.java:75)
  edu.ucr.cs.riple.core.registries.Registry.<init>(Registry.java:83)
  edu.ucr.cs.riple.core.registries.field.FieldRegistry.<init>(FieldRegistry.java:81)
  edu.ucr.cs.riple.core.module.ModuleInfo.<init>(ModuleInfo.java:91)
  edu.ucr.cs.riple.core.module.ModuleInfo.<init>(ModuleInfo.java:73)
  edu.ucr.cs.riple.core.Context.<init>(Context.java:78)
  edu.ucr.cs.riple.core.Annotator.<init>(Annotator.java:63)
  edu.ucr.cs.riple.core.Main.main(Main.java:45)

The parsing error is on ( but I managed to find the culprit! The code in question is as follows:

return object instanceof ImmutableEntry<?, ?>(var entry1) && entry1.equals(entry);

Let me know if I should report the issue to the other project or you will. Thanks!

To Reproduce
See the Java code above.

Expected behavior
No exception.

Stack trace
See above.

OS (please complete the following information):

  • OS: Linux
  • Version JDK 21
  • Annotator Version 1.3.13
@nimakarimipour
Copy link
Member

Hi @boris-petrov Thank you very much for reporting this issue. The code you provided is written with features specifically introduced in java 21 and it seems that Java parser has support for java up to 18 language levels. Unfortunately we cannot resolve this issue at this moment, unless javaparser adds the support for java 21. Let's keep this issue open so we can think more on this and find a solution for this in near future.

That would be great if you report the issue on their GitHub.
If it helps you can provide the code snippet below as a unit test that the code compiles successfully with java 21 and fails with java parser

public static void main(String[] args){
    StaticJavaParser.parse("public class Main {" +
            "    boolean run(Object object, ImmutableEntry<?, ?> entry) {" +
            "        return object instanceof ImmutableEntry<?, ?>(var entry1) && entry1.equals(entry);" +
            "    }" +
            "    record ImmutableEntry<K, V>(K key) {}" +
            "}");
  }

@nimakarimipour nimakarimipour added the long run A TODO for long run label Apr 4, 2024
@boris-petrov
Copy link
Author

@nimakarimipour I think they already have an issue for that so probably no need to open a new one.

As for my case - I'll try to rewrite this code to not use Java 21 features (I don't have that many cases) and then revert it once NullAwayAnnotator has done its job.

@jlerbsc
Copy link

jlerbsc commented Jul 13, 2024

Record Patterns is now supported on Javaparser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
long run A TODO for long run
Projects
None yet
Development

No branches or pull requests

3 participants