Commit 0be9af4de47b9ced7c53ac97d89d5d2197c5dfd6
1 parent
dca49895
fix(IotDeviceMessageUtils): skip JDK built-in types in reflection to avoid internal field access
Showing
1 changed file
with
5 additions
and
0 deletions
yudao-module-iot/yudao-module-iot-core/src/main/java/cn/iocoder/yudao/module/iot/core/util/IotDeviceMessageUtils.java
| 1 | package cn.iocoder.yudao.module.iot.core.util; | 1 | package cn.iocoder.yudao.module.iot.core.util; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.lang.Assert; | 3 | import cn.hutool.core.lang.Assert; |
| 4 | +import cn.hutool.core.util.ClassUtil; | ||
| 4 | import cn.hutool.core.util.IdUtil; | 5 | import cn.hutool.core.util.IdUtil; |
| 5 | import cn.hutool.core.util.ReflectUtil; | 6 | import cn.hutool.core.util.ReflectUtil; |
| 6 | import cn.hutool.core.util.StrUtil; | 7 | import cn.hutool.core.util.StrUtil; |
| @@ -83,6 +84,10 @@ public class IotDeviceMessageUtils { | @@ -83,6 +84,10 @@ public class IotDeviceMessageUtils { | ||
| 83 | if (params instanceof Map) { | 84 | if (params instanceof Map) { |
| 84 | return ((Map<?, ?>) params).get(fieldName); | 85 | return ((Map<?, ?>) params).get(fieldName); |
| 85 | } | 86 | } |
| 87 | + // 跳过 JDK 内置类型,避免反射读取到内部字段(例如 JDK8 下 String#value 会返回 char[]) | ||
| 88 | + if (ClassUtil.isJdkClass(params.getClass())) { | ||
| 89 | + return null; | ||
| 90 | + } | ||
| 86 | try { | 91 | try { |
| 87 | return ReflectUtil.getFieldValue(params, fieldName); | 92 | return ReflectUtil.getFieldValue(params, fieldName); |
| 88 | } catch (Exception ignored) { | 93 | } catch (Exception ignored) { |