unitsofmeasurement / indriya

JSR 385 - Reference Implementation
Other
115 stars 40 forks source link

NoClassDefFound when using with spring data redis #392

Open MehrCurry opened 1 year ago

MehrCurry commented 1 year ago

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.

keilw commented 1 year ago

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.

andi-huber commented 1 year ago

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

keilw commented 1 year ago

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?