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

SpEL expression on a reloadable type can no longer be resolved #31668

Closed
kzander91 opened this issue Nov 24, 2023 · 1 comment
Closed

SpEL expression on a reloadable type can no longer be resolved #31668

kzander91 opened this issue Nov 24, 2023 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: regression A bug that is also a regression
Milestone

Comments

@kzander91
Copy link
Contributor

kzander91 commented Nov 24, 2023

Starting with Boot 3.1.6/Framework 6.0.14, the following SpEL expression fails to resolve the referenced type, but only when devtools is on the classpath: T(com.example.MyEnum).VALUE
The following exception is thrown:

Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50)
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1005E: Type cannot be found 'com.example.demo.MyEnum'
        at org.springframework.expression.spel.support.StandardTypeLocator.findType(StandardTypeLocator.java:128)
        at org.springframework.expression.spel.ExpressionState.findType(ExpressionState.java:180)
        at org.springframework.expression.spel.ast.TypeReference.getValueInternal(TypeReference.java:70)
        at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:61)
        at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:97)
        at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:114)
        at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:142)
        at com.example.demo.DemoApplication.main(DemoApplication.java:15)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        ... 2 more

Downgrading to Framework 6.0.13, or removing devtools fixes it.

Reproducer: demo.zip

Main:

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);

        System.out.println(new SpelExpressionParser()
                .parseExpression("T(com.example.demo.MyEnum).VALUE")
                .getValue());
    }

}

MyEnum.java:

public enum MyEnum {
    VALUE
}

Extract and run ./mvnw spring-boot:run, the exception occurs.
Open the pom.xml and change the Spring Framework version to 6.0.13, run again and the code succeeds.
Alternatively, leave the Spring Framework version as is and remove the devtools dependency instead, run again and the code succeeds as well.

Maybe related: #31579

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 24, 2023
@snicoll snicoll transferred this issue from spring-projects/spring-boot Nov 24, 2023
@snicoll snicoll added type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 24, 2023
@snicoll snicoll added this to the 6.0.15 milestone Nov 24, 2023
@snicoll snicoll changed the title T() Operator cannot resolve type with Spring Framework 6.0.14 when spring-boot-devtools is on classpath SpEL expression on a reloadable type can no longer be resolved Nov 24, 2023
@jhoeller
Copy link
Contributor

jhoeller commented Nov 24, 2023

Ouch that's an oversight in the StandardTypeLocator cache handling where we mean to not cache if the class is reloadable, but the code path actually not just bypasses the cache, it also bypasses the return statement... Sorry for the glitch, we'll fix this ASAP.

@jhoeller jhoeller added the in: core Issues in core modules (aop, beans, core, context, expression) label Nov 24, 2023
@jhoeller jhoeller self-assigned this Nov 24, 2023
@jhoeller jhoeller modified the milestones: 6.0.15, 6.1.2 Nov 24, 2023
@jhoeller jhoeller added the for: backport-to-6.0.x Marks an issue as a candidate for backport to 6.0.x label Nov 24, 2023
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-6.0.x Marks an issue as a candidate for backport to 6.0.x labels Nov 24, 2023
jhoeller added a commit that referenced this issue Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

4 participants