Browse Source

Use Set to track ignored properties in BeanUtils.copyProperties()

Closes gh-30088
pull/30096/head
liupeng 2 years ago committed by Sam Brannen
parent
commit
d2868f5dd0
  1. 5
      spring-beans/src/main/java/org/springframework/beans/BeanUtils.java

5
spring-beans/src/main/java/org/springframework/beans/BeanUtils.java

@ -29,6 +29,7 @@ import java.time.temporal.Temporal; @@ -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 { @@ -791,11 +792,11 @@ public abstract class BeanUtils {
actualEditable = editable;
}
PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable);
List<String> ignoreList = (ignoreProperties != null ? Arrays.asList(ignoreProperties) : null);
Set<String> 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();

Loading…
Cancel
Save