From d2868f5dd0840c158a5a60fa96c4afd9ce19f777 Mon Sep 17 00:00:00 2001 From: liupeng Date: Thu, 9 Mar 2023 02:07:57 +0800 Subject: [PATCH] Use Set to track ignored properties in BeanUtils.copyProperties() Closes gh-30088 --- .../src/main/java/org/springframework/beans/BeanUtils.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java b/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java index 7647f4b667e..535bf8e8932 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java @@ -29,6 +29,7 @@ import java.time.temporal.Temporal; import java.util.Arrays; import java.util.Collections; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; @@ -791,11 +792,11 @@ public abstract class BeanUtils { actualEditable = editable; } PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable); - List ignoreList = (ignoreProperties != null ? Arrays.asList(ignoreProperties) : null); + Set ignoreSet = (ignoreProperties != null ? new HashSet<>(Arrays.asList(ignoreProperties)) : null); for (PropertyDescriptor targetPd : targetPds) { Method writeMethod = targetPd.getWriteMethod(); - if (writeMethod != null && (ignoreList == null || !ignoreList.contains(targetPd.getName()))) { + if (writeMethod != null && (ignoreSet == null || !ignoreSet.contains(targetPd.getName()))) { PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), targetPd.getName()); if (sourcePd != null) { Method readMethod = sourcePd.getReadMethod();