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]: JLSViolation occurs when using a setter method created using Lombok's @Setter annotation #5903

Open
ValeryKomarov opened this issue Aug 1, 2024 · 1 comment
Labels

Comments

@ValeryKomarov
Copy link

Describe the bug

In the test project at this link (https://github.com/ValeryKomarov/SpoonSingleQuoteLombokIssue), a JLSViolation exception occurs, in the method on this line https://github.com/ValeryKomarov/SpoonSingleQuoteLombokIssue/blob/3d0d5456e9d72f274de3d1847f257bebd7875468/src/main/java/com/pvsstudio/lombok/issue/UseLombokExample.java#L17

Source code you are trying to analyze/transform

package com.pvsstudio.lombok.issue;

import lombok.Setter;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class UseLombokExample {
    @Setter
    private List<String> stringList = new ArrayList<>();

    static void testMethodExample() {
        Set<String> hashSet = new HashSet<>();

        new UseLombokExample().setStringList(new ArrayList<>(hashSet)); // JLSViolation

        // new UseLombokExample().setStringList(new ArrayList<>()); // No JLSViolation
    }

}

Source code for your Spoon processing

package com.pvsstudio.lombok.issue;

import spoon.MavenLauncher;
import spoon.reflect.CtModel;

public class Main {
    public static void main(String[] args) {
        MavenLauncher launcher = new MavenLauncher(
            ".",
            MavenLauncher.SOURCE_TYPE.APP_SOURCE);

        CtModel model = launcher.buildModel();
    }
}

Actual output

C:\Users\komarov\.jdks\corretto-17.0.12\bin\java.exe "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.1.4\lib\idea_rt.jar=58996:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.1.4\bin" -Dfile.encoding=UTF-8 -classpath C:\WORK_PVS\SpoonSingleQuoteLombokIssue\target\classes;C:\Users\komarov\.m2\repository\fr\inria\gforge\spoon\spoon-core\11.0.0\spoon-core-11.0.0.jar;C:\Users\komarov\.m2\repository\org\eclipse\jdt\org.eclipse.jdt.core\3.37.0\org.eclipse.jdt.core-3.37.0.jar;C:\Users\komarov\.m2\repository\org\eclipse\jdt\ecj\3.37.0\ecj-3.37.0.jar;C:\Users\komarov\.m2\repository\com\martiansoftware\jsap\2.1\jsap-2.1.jar;C:\Users\komarov\.m2\repository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;C:\Users\komarov\.m2\repository\commons-io\commons-io\2.16.0\commons-io-2.16.0.jar;C:\Users\komarov\.m2\repository\org\apache\maven\maven-model\3.6.0\maven-model-3.6.0.jar;C:\Users\komarov\.m2\repository\org\codehaus\plexus\plexus-utils\3.1.0\plexus-utils-3.1.0.jar;C:\Users\komarov\.m2\repository\org\apache\commons\commons-lang3\3.14.0\commons-lang3-3.14.0.jar;C:\Users\komarov\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.17.0\jackson-databind-2.17.0.jar;C:\Users\komarov\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.17.0\jackson-annotations-2.17.0.jar;C:\Users\komarov\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.17.0\jackson-core-2.17.0.jar;C:\Users\komarov\.m2\repository\net\bytebuddy\byte-buddy\1.14.9\byte-buddy-1.14.9.jar;C:\Users\komarov\.m2\repository\org\apache\commons\commons-compress\1.26.1\commons-compress-1.26.1.jar;C:\Users\komarov\.m2\repository\commons-codec\commons-codec\1.16.1\commons-codec-1.16.1.jar;C:\Users\komarov\.m2\repository\org\jspecify\jspecify\0.3.0\jspecify-0.3.0.jar;C:\Users\komarov\.m2\repository\org\apache\maven\shared\maven-invoker\3.2.0\maven-invoker-3.2.0.jar;C:\Users\komarov\.m2\repository\org\apache\maven\shared\maven-shared-utils\3.3.4\maven-shared-utils-3.3.4.jar;C:\Users\komarov\.m2\repository\javax\inject\javax.inject\1\javax.inject-1.jar com.pvsstudio.lombok.issue.Main
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" spoon.JLSViolation: Not allowed javaletter or keyword in identifier found. See JLS for correct identifier. Identifier: E'
	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:893)
	at org.eclipse.jdt.internal.compiler.ast.AllocationExpression.traverse(AllocationExpression.java:730)
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.traverse(MessageSend.java:1278)
	at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.traverse(MethodDeclaration.java:456)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1716)
	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:504)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.lambda$buildModel$0(JDTBasedSpoonCompiler.java:461)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.forEachCompilationUnit(JDTBasedSpoonCompiler.java:488)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildModel(JDTBasedSpoonCompiler.java:459)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildUnitsAndModel(JDTBasedSpoonCompiler.java:388)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildSources(JDTBasedSpoonCompiler.java:346)
	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)
	at com.pvsstudio.lombok.issue.Main.main(Main.java:12)

Process finished with exit code 1

Expected output

C:\Users\komarov\.jdks\corretto-17.0.12\bin\java.exe "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.1.4\lib\idea_rt.jar=59000:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.1.4\bin" -Dfile.encoding=UTF-8 -classpath C:\WORK_PVS\SpoonSingleQuoteLombokIssue\target\classes;C:\Users\komarov\.m2\repository\fr\inria\gforge\spoon\spoon-core\11.0.0\spoon-core-11.0.0.jar;C:\Users\komarov\.m2\repository\org\eclipse\jdt\org.eclipse.jdt.core\3.37.0\org.eclipse.jdt.core-3.37.0.jar;C:\Users\komarov\.m2\repository\org\eclipse\jdt\ecj\3.37.0\ecj-3.37.0.jar;C:\Users\komarov\.m2\repository\com\martiansoftware\jsap\2.1\jsap-2.1.jar;C:\Users\komarov\.m2\repository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;C:\Users\komarov\.m2\repository\commons-io\commons-io\2.16.0\commons-io-2.16.0.jar;C:\Users\komarov\.m2\repository\org\apache\maven\maven-model\3.6.0\maven-model-3.6.0.jar;C:\Users\komarov\.m2\repository\org\codehaus\plexus\plexus-utils\3.1.0\plexus-utils-3.1.0.jar;C:\Users\komarov\.m2\repository\org\apache\commons\commons-lang3\3.14.0\commons-lang3-3.14.0.jar;C:\Users\komarov\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.17.0\jackson-databind-2.17.0.jar;C:\Users\komarov\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.17.0\jackson-annotations-2.17.0.jar;C:\Users\komarov\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.17.0\jackson-core-2.17.0.jar;C:\Users\komarov\.m2\repository\net\bytebuddy\byte-buddy\1.14.9\byte-buddy-1.14.9.jar;C:\Users\komarov\.m2\repository\org\apache\commons\commons-compress\1.26.1\commons-compress-1.26.1.jar;C:\Users\komarov\.m2\repository\commons-codec\commons-codec\1.16.1\commons-codec-1.16.1.jar;C:\Users\komarov\.m2\repository\org\jspecify\jspecify\0.3.0\jspecify-0.3.0.jar;C:\Users\komarov\.m2\repository\org\apache\maven\shared\maven-invoker\3.2.0\maven-invoker-3.2.0.jar;C:\Users\komarov\.m2\repository\org\apache\maven\shared\maven-shared-utils\3.3.4\maven-shared-utils-3.3.4.jar;C:\Users\komarov\.m2\repository\javax\inject\javax.inject\1\javax.inject-1.jar com.pvsstudio.lombok.issue.Main
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" spoon.compiler.ModelBuildingException: The import lombok cannot be resolved at C:\WORK_PVS\SpoonSingleQuoteLombokIssue\src\main\java\com\pvsstudio\lombok\issue\UseLombokExample.java:3
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.report(JDTBasedSpoonCompiler.java:663)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.reportProblems(JDTBasedSpoonCompiler.java:645)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:119)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:100)
	at spoon.Launcher.buildModel(Launcher.java:781)
	at com.pvsstudio.lombok.issue.Main.main(Main.java:12)

Process finished with exit code 1

Spoon Version

11.0.0

JVM Version

17

What operating system are you using?

Windows

@MartinWitt
Copy link
Collaborator

Hey, I believe this is fixed in #5844. Can you use our snapshot builds to test this?

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

No branches or pull requests

2 participants