java runtime_error ai_generated true

java.lang.reflect.MalformedParameterizedTypeException

ID: java/malformed-parameterized-type

Also available as: JSON · Markdown · 中文
78%Fix Rate
83%Confidence
1Evidence
2024-06-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Java 8 active
Java 11 active
Java 17 active
Spring Boot 2.7.18 active
Spring Boot 3.2.0 active
Hibernate 5.6.15 active
Hibernate 6.4.0 active

Root Cause

The JVM's reflection system encountered a malformed parameterized type signature, typically caused by bytecode manipulation libraries (like ASM, CGLIB, or ByteBuddy) generating incorrect generic type information, or by incompatibilities between library versions.

generic

中文

JVM的反射系统遇到格式错误的参数化类型签名,通常是由字节码操作库(如ASM、CGLIB或ByteBuddy)生成不正确的泛型类型信息,或库版本不兼容引起的。

Official Documentation

https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/reflect/MalformedParameterizedTypeException.html

Workarounds

  1. 80% success Identify the conflicting library using the stack trace. For example, if the trace shows `net.sf.cglib.proxy.MethodProxy`, ensure CGLIB version is compatible with the ASM version. Use Maven's dependency tree: `mvn dependency:tree -Dincludes=*cglib*` and align versions. Example: use CGLIB 3.3.0 with ASM 9.5.
    Identify the conflicting library using the stack trace. For example, if the trace shows `net.sf.cglib.proxy.MethodProxy`, ensure CGLIB version is compatible with the ASM version. Use Maven's dependency tree: `mvn dependency:tree -Dincludes=*cglib*` and align versions. Example: use CGLIB 3.3.0 with ASM 9.5.
  2. 75% success If using Spring Boot with AOP proxies, switch from CGLIB proxies to JDK dynamic proxies by setting `spring.aop.proxy-target-class=false` in application.properties. This avoids the bytecode manipulation that triggers the error.
    If using Spring Boot with AOP proxies, switch from CGLIB proxies to JDK dynamic proxies by setting `spring.aop.proxy-target-class=false` in application.properties. This avoids the bytecode manipulation that triggers the error.
  3. 70% success Rebuild the project with a clean cache: `mvn clean install -U` (Maven) or `gradle clean build --refresh-dependencies` (Gradle). This ensures all bytecode artifacts are regenerated from source, eliminating stale or corrupted class files.
    Rebuild the project with a clean cache: `mvn clean install -U` (Maven) or `gradle clean build --refresh-dependencies` (Gradle). This ensures all bytecode artifacts are regenerated from source, eliminating stale or corrupted class files.

中文步骤

  1. Identify the conflicting library using the stack trace. For example, if the trace shows `net.sf.cglib.proxy.MethodProxy`, ensure CGLIB version is compatible with the ASM version. Use Maven's dependency tree: `mvn dependency:tree -Dincludes=*cglib*` and align versions. Example: use CGLIB 3.3.0 with ASM 9.5.
  2. If using Spring Boot with AOP proxies, switch from CGLIB proxies to JDK dynamic proxies by setting `spring.aop.proxy-target-class=false` in application.properties. This avoids the bytecode manipulation that triggers the error.
  3. Rebuild the project with a clean cache: `mvn clean install -U` (Maven) or `gradle clean build --refresh-dependencies` (Gradle). This ensures all bytecode artifacts are regenerated from source, eliminating stale or corrupted class files.

Dead Ends

Common approaches that don't work:

  1. Upgrade all dependencies to the latest versions indiscriminately 60% fail

    Blindly upgrading can introduce new incompatibilities. The issue is often a specific version mismatch between a bytecode library and the JVM or framework. Targeted upgrades with compatibility testing are needed.

  2. Add @SuppressWarnings("unchecked") or ignore the exception 95% fail

    The exception is thrown at runtime and cannot be suppressed by annotations. Ignoring it will cause the application to crash or behave incorrectly when reflection is used.