indriya icon indicating copy to clipboard operation
indriya copied to clipboard

NoClassDefFound when using with spring data redis

Open MehrCurry opened this issue 3 years ago • 3 comments

I am trying to use UOM together with spring data redis to persist some values.

When saving the Object i always get the following error:

Caused by: java.lang.NoClassDefFoundError: IllegalName: tech.units.indriya.unit.ProductUnit$$Lambda$1208/0x0000000801204e70_Accessor_5hp3zf
	at java.base/java.lang.ClassLoader.preDefineClass(ClassLoader.java:886) ~[na:na]
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
	at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:506) ~[spring-core-6.0.3.jar:6.0.3]

Any hints how it is meant to be serialized?

I am using Spring Boot 3 on Java 17 with Indriya 2.1.3.

MehrCurry avatar Jan 23 '23 07:01 MehrCurry

Can you share more details or code snippets to reproduce? It might be a problem of Spring and reflection under Java 17, there are some things that got more restrictive with every version. Did you ask the Spring Framework Core team about the error in ReflectUtils? ProductUnit inherits from AbstractUnit which is Serializable, so there is no serialization issue as such.

@andi-huber Any idea what the $$Lambda$$ might mean, because at least inside ProductUnit itself I could not see lambda expressions either.

keilw avatar Jan 23 '23 09:01 keilw

Could be CGLIB related. Which I thought is no longer recommended to be used.

andi-huber avatar Jan 23 '23 09:01 andi-huber

Thanks for the input @andi-huber, then @MehrCurry could you please ask the Spring team why they're still using CGLIB and if there is another option you may try?

keilw avatar Jan 23 '23 16:01 keilw