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]: Type reference building logic fails within lambda bodies #5477

Open
lukebemish opened this issue Sep 28, 2023 · 0 comments
Open

[Bug]: Type reference building logic fails within lambda bodies #5477

lukebemish opened this issue Sep 28, 2023 · 0 comments
Labels

Comments

@lukebemish
Copy link

lukebemish commented Sep 28, 2023

Describe the bug

Something seems to go wrong with type reference parsing within method bodies when extends is involved. The following fails with the included stack trace:

Launcher.parseClass("""
    public class Test {
        public static void test() {
            final Supplier<Object> supplier = () -> {
                final Supplier<? extends Function<?, Object>> supplier1 = () -> a -> a;
                return supplier1;
            };
        }
    }""");

However, each of the following succeed:

Launcher.parseClass("""
    public class Test {
        public static void test() {
            final Supplier<Object> supplier = () -> {
                final Supplier<Function<?, Object>> supplier1 = () -> a -> a;
                return supplier1;
            };
        }
    }""");
Launcher.parseClass("""
    public class Test {
        public static void test() {
            final Supplier<Object> supplier = () -> {
                final Supplier<? extends Supplier<?>> supplier1 = () -> () -> new Object();
                return supplier1;
            };
        }
    }""");
Launcher.parseClass("""
    public class Test {
        public static void test() {
            final Supplier<? extends Function<?, Object>> supplier = () -> a -> a;
        }
    }""");

In other words, it only seems to apply with the combination of the local definition being within a lambda, the extends being present, and the nested type being parameterized by more than one type (so that it is split on the comma when the outer one is being processed)

Actual output

Caused by: spoon.JLSViolation: Not allowed javaletter or keyword in identifier found. See JLS for correct identifier. Identifier: Function<?
        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.getTypeReference(ReferenceBuilder.java:799)
        at spoon.support.compiler.jdt.ReferenceBuilder.getTypeParameterReference(ReferenceBuilder.java:818)
        at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReference(ReferenceBuilder.java:788)
        at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReference(ReferenceBuilder.java:734)
        at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReference(ReferenceBuilder.java:613)
        at spoon.support.compiler.jdt.ReferenceBuilder.buildTypeReference(ReferenceBuilder.java:139)
        at spoon.support.compiler.jdt.ReferenceBuilder.buildTypeReference(ReferenceBuilder.java:133)
        at spoon.support.compiler.jdt.JDTTreeBuilder.createParameterizedType(JDTTreeBuilder.java:1479)
        at spoon.support.compiler.jdt.JDTTreeBuilder.visit(JDTTreeBuilder.java:1467)
        at org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference.traverse(ParameterizedSingleTypeReference.java:405)
        at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.traverse(LocalDeclaration.java:482)
        at org.eclipse.jdt.internal.compiler.ast.Block.traverse(Block.java:154)
        at org.eclipse.jdt.internal.compiler.ast.LambdaExpression.traverse(LambdaExpression.java:795)
        at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.traverse(LocalDeclaration.java:484)
        at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.traverse(MethodDeclaration.java:437)
        at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1702)
        at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:827)
        at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:788)
        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)
        at spoon.Launcher.parseClass(Launcher.java:889)

Spoon Version

10.4.2-beta-4, tried on 10.4.1 as well

JVM Version

17.0.8.1

What operating system are you using?

Kubuntu

@lukebemish lukebemish added the bug label Sep 28, 2023
@lukebemish lukebemish changed the title [Bug]: ReferenceBuilder#getTypeReference logic fails within lambda bodies [Bug]: Type reference building logic fails within lambda bodies Sep 28, 2023
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

1 participant