Переглянути джерело

!182 修复 JDK16 中增加模块化校验后,导致 lambda 序列化失败问题
Merge pull request !182 from 你有医保你先上/3.0

青苗 3 роки тому
батько
коміт
f2608a1067

+ 4 - 3
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/LambdaUtils.java

@@ -60,10 +60,11 @@ public final class LambdaUtils {
             throw new MybatisPlusException(message);
         } catch (InvocationTargetException | IllegalAccessException e) {
             throw new MybatisPlusException(e);
-        } catch (RuntimeException e) {
-            // JDK 16 模块化后不能访问 java.lang.invoke.SerializedLambda 了,走序列化路线
+        } catch (Error e) {
+            // JDK 16 模块化后不能使用反射访问其他模块的字段,因此这里需要使用序列化的方式进行处理
             // https://gitee.com/baomidou/mybatis-plus/issues/I3XDT9
-            if (e.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) {
+            Throwable cause = e.getCause();
+            if (cause != null && cause.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) {
                 return new ShadowLambdaMeta(com.baomidou.mybatisplus.core.toolkit.support.SerializedLambda.extract(func));
             }
             throw e;