Hi,
I recently opened an issue to track the needed stuff for Spring-Boot in order to support Java 17. https://github.com/spring-projects/spring-boot/issues/26767. I think it makes sense to have the same for Spring Framework.
Known issues:
- Sealed interfaces need to be handled e.g. when creating proxies.
@Bean
@Scope(proxyMode = ScopedProxyMode.INTERFACES)
String alpha() {
return "alpha";
}
Essentially, under the hood it retrieves all interfaces of String
here which also includes ConstantDesc
which is a sealed interface and cannot be used when creating a proxy. See ScopedProxyFactoryBean.setBeanFactory
:
if (!isProxyTargetClass() || beanType.isInterface() || Modifier.isPrivate(beanType.getModifiers())) {
// This should filter sealed interfaces I guess
pf.setInterfaces(ClassUtils.getAllInterfacesForClass(beanType, cbf.getBeanClassLoader()));
}
After a first look this probably needs to be handled more centrally and more places are potentially affected by sealed interfaces.
There is likely more to do for Java 17 support, but I wanted to kick this off. Feel free to add to this issue or repurpose it to only handle the specific issue.
Let me know if I can help.
Cheers, Christoph
Comment From: jhoeller
It seems sufficient to exclude sealed interfaces through a reflective Class.isSealed()
check in the AopProxyUtils.completeProxiedInterfaces
algorithm. I've locally tested this on JDK 17, seems to work fine so far. This will be in main for 5.3.9 tonight, would be great to know whether it also works for a Boot setup then...
Comment From: dreis2211
I will give it a try tomorrow. Thanks @jhoeller
Comment From: dreis2211
Seems to work just fine for the failing test in Boot.
Comment From: jhoeller
Cool, thanks for the quick turnaround!
Comment From: quaff
@jhoeller Should sealed interfaces be filtered here? https://github.com/spring-projects/spring-framework/blob/b595dc1dfad9db534ca7b9e8f46bb9926b88ab5a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactory.java#L51
see https://bugs.openjdk.java.net/browse/JDK-8269396
Comment From: LifeIsStrange
What about Kotlin sealed classes? Maybe that the same solution could be used given that Kotlin is making their sealed classes more interoperable/aligned with Java ones https://youtrack.jetbrains.com/issue/KT-46778
Also note that for kotlin reflection might not be needed in the future https://youtrack.jetbrains.com/issue/KT-25871 And that inline sealed classes are a thing https://youtrack.jetbrains.com/issue/KT-27576
Maybe that none of those things are relevant (haven't looked into this issue) but I wanted to share this, just in case