From 3cbbbcfe1ba34da4c3858f4a0eb3c3ff08eef5b1 Mon Sep 17 00:00:00 2001 From: Looly Date: Wed, 5 Jul 2023 09:45:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DBeanUtil.isCommonFieldsEqual?= =?UTF-8?q?=E5=88=A4=E7=A9=BA=E5=AF=BC=E8=87=B4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 ++- .../src/main/java/cn/hutool/core/bean/BeanUtil.java | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 035265c15..454d61091 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ # 🚀Changelog ------------------------------------------------------------------------------------------------------------- -# 5.8.21(2023-07-03) +# 5.8.21(2023-07-05) ### 🐣新特性 * 【core 】 list 为空时,CollUtil.max等返回null而非异常(pr#1027@Gitee) @@ -20,6 +20,7 @@ * 【core 】 修复PathUtil.getMimeType可能造成的异常(issue#3179@Github) * 【core 】 修复Pair序列化转换无效问题(issue#I7GPGX@Github) * 【core 】 修复TypeUtil.getTypeArgument对实现接口获取不全面问题(issue#I7CRIW@Gitee) +* 【core 】 修复BeanUtil.isCommonFieldsEqual判空导致的问题 ------------------------------------------------------------------------------------------------------------- # 5.8.20(2023-06-16) diff --git a/hutool-core/src/main/java/cn/hutool/core/bean/BeanUtil.java b/hutool-core/src/main/java/cn/hutool/core/bean/BeanUtil.java index 142ec7ec7..84cae5a15 100755 --- a/hutool-core/src/main/java/cn/hutool/core/bean/BeanUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/bean/BeanUtil.java @@ -994,15 +994,17 @@ public class BeanUtil { return false; } - Map sourceFieldsMap = BeanUtil.beanToMap(source); - Map targetFieldsMap = BeanUtil.beanToMap(target); + final Map sourceFieldsMap = BeanUtil.beanToMap(source); + final Map targetFieldsMap = BeanUtil.beanToMap(target); - Set sourceFields = sourceFieldsMap.keySet(); + final Set sourceFields = sourceFieldsMap.keySet(); sourceFields.removeAll(Arrays.asList(ignoreProperties)); for (String field : sourceFields) { - if (ObjectUtil.notEqual(sourceFieldsMap.get(field), targetFieldsMap.get(field))) { - return false; + if(sourceFieldsMap.containsKey(field) && targetFieldsMap.containsKey(field)){ + if (ObjectUtil.notEqual(sourceFieldsMap.get(field), targetFieldsMap.get(field))) { + return false; + } } }