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

[Bug]: Not allowed javaletter or keyword in identifier found #5591

Closed
callain-mirakl opened this issue Dec 21, 2023 · 5 comments · Fixed by #5844
Closed

[Bug]: Not allowed javaletter or keyword in identifier found #5591

callain-mirakl opened this issue Dec 21, 2023 · 5 comments · Fixed by #5844
Labels

Comments

@callain-mirakl
Copy link

Describe the bug

Hello, I have this error, even with the latest version. Could you tell me how I can debug the execution to see which files cause the issue? Thanks.

[ERROR] Unexpected error
spoon.JLSViolation: Not allowed javaletter or keyword in identifier found. See JLS for correct identifier. Identifier: K'
    at spoon.JLSViolation.throwIfSyntaxErrorsAreNotIgnored (JLSViolation.java:38)

Source code you are trying to analyze/transform

No response

Source code for your Spoon processing

No response

Actual output

No response

Expected output

No response

Spoon Version

10.4.2

JVM Version

openjdk 17.0.7 2023-04-18 LTS OpenJDK Runtime Environment Zulu17.42+19-CA (build 17.0.7+7-LTS) OpenJDK 64-Bit Server VM Zulu17.42+19-CA (build 17.0.7+7-LTS, mixed mode, sharing)

What operating system are you using?

macOS

@callain-mirakl callain-mirakl changed the title [Bug]: [Bug]: Not allowed javaletter or keyword in identifier found Dec 21, 2023
@MartinWitt
Copy link
Collaborator

Hey,

For a CtElement with a position you can use element.getPosition().getFile(). Providing a reproduction example or instruction what you are doing is necessary for us to debug this.

@callain-mirakl
Copy link
Author

My coworker managed to reproduce the issue during my holidays, the solution we implemented is to use a variable to store the instance of the new HashMap

Problem

package com.demo;

import java.util.HashMap;
import java.util.Map;

public class TestClass {

    private final Map<String, Object> testMap;

    public TestClass() {
        this.testMap = Map.of("TEST", true);
    }

    public Boolean myTest() {
        var redirectView = Boolean.TRUE;
        return test(redirectView, new HashMap<>(testMap));
    }


    private Boolean test(final Boolean redirectView, final Map<String, Object> params) {
        params.put("TEST", "TEST");
        return redirectView;
    }
}

Solution

public Boolean myTest() {
    var redirectView = Boolean.TRUE;
    var solution = new HashMap<>(testMap);
    return test(redirectView, solution);
}

@tenax66
Copy link
Contributor

tenax66 commented Jan 17, 2024

Do you mean that JLSViolation error occurred when the code you provided was analyzed by spoon?
Could you also provide the spoon code used for the analysis?

@callain-mirakl
Copy link
Author

Yes, I've extracted the code of the launcher

        String path = "src/test/java";
        String basedir = new File(path).getAbsolutePath();
        Launcher launcher = new Launcher();
        launcher.getEnvironment().setNoClasspath(true);
        launcher.addInputResource(basedir);
        launcher.buildModel();

And here is the complete stack

spoon.JLSViolation: Not allowed javaletter or keyword in identifier found. See JLS for correct identifier. Identifier: K'
        at spoon.JLSViolation.throwIfSyntaxErrorsAreNotIgnored(JLSViolation.java:38)
        at spoon.support.reflect.reference.CtReferenceImpl.checkIdentifierForJLSCorrectness(CtReferenceImpl.java:114)
        at spoon.support.reflect.reference.CtReferenceImpl.setSimpleName(CtReferenceImpl.java:57)
        at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReferenceFromTypeVariableBinding(ReferenceBuilder.java:1026)
        at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReference(ReferenceBuilder.java:863)
        at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReference(ReferenceBuilder.java:842)
        at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReferenceFromWildcardBinding(ReferenceBuilder.java:1107)
        at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReference(ReferenceBuilder.java:867)
        at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReference(ReferenceBuilder.java:842)
        at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReferenceFromTypeArgument(ReferenceBuilder.java:976)
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
        at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:992)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
        at spoon.support.compiler.jdt.ReferenceBuilder.getTypeArguments(ReferenceBuilder.java:961)
        at spoon.support.compiler.jdt.ReferenceBuilder.getParameterizedTypeReference(ReferenceBuilder.java:948)
        at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReference(ReferenceBuilder.java:857)
        at spoon.support.compiler.jdt.ReferenceBuilder.getExecutableReference(ReferenceBuilder.java:475)
        at spoon.support.compiler.jdt.ReferenceBuilder.getExecutableReference(ReferenceBuilder.java:414)
        at spoon.support.compiler.jdt.ReferenceBuilder.getExecutableReference(ReferenceBuilder.java:493)
        at spoon.support.compiler.jdt.JDTTreeBuilder.visit(JDTTreeBuilder.java:880)
        at org.eclipse.jdt.internal.compiler.ast.AllocationExpression.traverse(AllocationExpression.java:727)
        at org.eclipse.jdt.internal.compiler.ast.MessageSend.traverse(MessageSend.java:1176)
        at org.eclipse.jdt.internal.compiler.ast.ReturnStatement.traverse(ReturnStatement.java:392)
        at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.traverse(MethodDeclaration.java:437)
        at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1700)
        at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:829)
        at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:790)
        at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.traverseUnitDeclaration(JDTBasedSpoonCompiler.java:481)
        at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.lambda$buildModel$0(JDTBasedSpoonCompiler.java:438)
        at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.forEachCompilationUnit(JDTBasedSpoonCompiler.java:465)
        at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildModel(JDTBasedSpoonCompiler.java:436)
        at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildUnitsAndModel(JDTBasedSpoonCompiler.java:373)
        at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildSources(JDTBasedSpoonCompiler.java:336)
        at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:117)
        at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:100)
        at spoon.Launcher.buildModel(Launcher.java:781)

@tenax66
Copy link
Contributor

tenax66 commented Jan 21, 2024

Does the src/test/java folder containing TestClass cause the error?
I could not reproduce it.

Could you provide a minimal example that reproduces the problem? Please also try the approach that MartinWitt commented on.

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

Successfully merging a pull request may close this issue.

3 participants