8000 Generate compiled SpEL expressions using Java 17 byte code level · Issue #34602 · spring-projects/spring-framework · GitHub
[go: up one dir, main page]

Skip to content

Generate compiled SpEL expressions using Java 17 byte code level #34602

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

Closed
sbrannen opened this issue Mar 14, 2025 · 1 comment
Closed

Generate compiled SpEL expressions using Java 17 byte code level #34602

sbrannen opened this issue Mar 14, 2025 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@sbrannen
Copy link
Member
sbrannen commented Mar 14, 2025

When generating dynamic classes with CGLIB or compiling SpEL expressions, we currently generate byte code with Java 8 byte code level.

For Spring Framework 7, we should generate byte code with Java 17 byte code level to align with the Java 17 baseline introduced in Spring Framework 6.0.

@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Mar 14, 2025
@sbrannen sbrannen added this to the 7.0.0-M4 milestone Mar 14, 2025
@sbrannen sbrannen self-assigned this Mar 14, 2025
@sbrannen
Copy link
Member Author

Unfortunately, it is not possible to raise the byte code level beyond Java 1.8 for classes generated using CGLIB due to the fact that CGLIB generates STATICHOOK methods which set static final fields outside the initializer method <clinit> (i.e., a static initialization block).

Attempting to raise the level to Java 17 (or even Java 9) results in exceptions like the following.

Caused by: java.lang.IllegalAccessError: Update to static final field org.example.MyBean$$SpringCGLIB$$0.CGLIB$THREAD_CALLBACKS attempted from a different method (CGLIB$STATICHOOK1) than the initializer method <clinit>
	at org.example.MyBean$$SpringCGLIB$$0.CGLIB$STATICHOOK1(<generated>)
	at org.example.MyBean$$SpringCGLIB$$0.<clinit>(<generated>)

We will therefore leave the version set to 1.8 for CGLIB.

@sbrannen sbrannen changed the title Generate byte code with Java 17 class version Generate compiled SpEL expressions using Java 17 byte code level Mar 18, 2025
sbrannen added a commit that referenced this issue Mar 18, 2025
Unfortunately, it is not possible to raise the byte code level beyond
Java 1.8 for classes generated using CGLIB due to the fact that CGLIB
generates STATICHOOK methods which set static final fields outside the
initializer method <clinit> (i.e., a static initialization block).

Attempting to raise the level to Java 17 (or even Java 9) results in
exceptions like the following.

Caused by: java.lang.IllegalAccessError: Update to static final field
  org.example.MyBean$$SpringCGLIB$$0.CGLIB$THREAD_CALLBACKS attempted from
  a different method (CGLIB$STATICHOOK1) than the initializer method <clinit>
    at org.example.MyBean$$SpringCGLIB$$0.CGLIB$STATICHOOK1(<generated>)
    at org.example.MyBean$$SpringCGLIB$$0.<clinit>(<generated>)

This commit therefore introduces inline comments pointing out why we
stay with Java 1.8 byte code level with CGLIB.

See gh-34602
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) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant
0