javaparser icon indicating copy to clipboard operation
javaparser copied to clipboard

Undescriptive error message when language level is mismatched

Open DLochmelis33 opened this issue 8 months ago • 1 comments

Upon analyzing this file:


// [ many other methods go here ]

public static void main(String[] args) {
    try (Scanner input = new Scanner(System.in)) {
        System.out.println("Enter (e) letter for encrpyt or (d) letter for decrypt :");
        char choice = input.nextLine().charAt(0);
        String in;
        switch (choice) {
            case 'E', 'e' -> {
                System.out.println(
                        "Choose a plaintext block (128-Bit Integer in base 16):"
                );
                in = input.nextLine();
                BigInteger plaintext = new BigInteger(in, 16);
                System.out.println(
                        "Choose a Key (128-Bit Integer in base 16):"
                );
                in = input.nextLine();
                BigInteger encryptionKey = new BigInteger(in, 16);
                System.out.println(
                        "The encrypted message is: \n"
                                + encrypt(plaintext, encryptionKey).toString(16)
                );
            }
            case 'D', 'd' -> {
                System.out.println(
                        "Enter your ciphertext block (128-Bit Integer in base 16):"
                );
                in = input.nextLine();
                BigInteger ciphertext = new BigInteger(in, 16);
                System.out.println(
                        "Choose a Key (128-Bit Integer in base 16):"
                );
                in = input.nextLine();
                BigInteger decryptionKey = new BigInteger(in, 16);
                System.out.println(
                        "The deciphered message is:\n"
                                + decrypt(ciphertext, decryptionKey).toString(16)
                );
            }
            default -> System.out.println("** End **");
        }
    }
}

I get the following error when trying to resolve any other method parameters:

Exception in thread "main" java.lang.IllegalStateException: Symbol resolution not configured: to configure consider setting a SymbolResolver in the ParserConfiguration
	at com.github.javaparser.ast.Node.lambda$getSymbolResolver$9(Node.java:841)
	at java.base/java.util.Optional.map(Optional.java:260)
	at com.github.javaparser.ast.Node.getSymbolResolver(Node.java:837)
	at com.github.javaparser.ast.expr.NameExpr.resolve(NameExpr.java:164)

...when symbol resolution was in fact configured, and worked fine for many other files. After a long while of debugging (and talking to LLMs) I was able to pinpoint the issue to the main method and not the method under analysis. Turns out I did not setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_21), and after setting it, the issue went away.

However, the error message is extremely undescriptive. It throws the user off into a wrong direction of debugging. A much more reasonable error would be to fail parsing the file completely, indicating that language level may be wrong.

DLochmelis33 avatar Apr 18 '25 11:04 DLochmelis33

Can you show us how you set up JP?

jlerbsc avatar Apr 18 '25 14:04 jlerbsc

Hey, Could my team and I work on resolving this issue for a university project?

Thanks

TeeleTitan avatar Oct 14 '25 05:10 TeeleTitan

Thank you for your proposition but there is no subject here. Before using JP, you need to read through some documentation to learn how to use JP. In this case, it is indeed a parser configuration issue.

jlerbsc avatar Oct 14 '25 08:10 jlerbsc