Suppress NotWritablePropertyException in case of ignoreUnknown=true
Closes gh-25986
This commit is contained in:
parent
990a9c74b9
commit
97c8628bd6
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -422,9 +422,12 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
if (this.suppressNotWritablePropertyException) {
|
||||||
throw createNotWritablePropertyException(tokens.canonicalName);
|
// Optimization for common ignoreUnknown=true scenario since the
|
||||||
|
// exception would be caught and swallowed higher up anyway...
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
throw createNotWritablePropertyException(tokens.canonicalName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object oldValue = null;
|
Object oldValue = null;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2018 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -40,6 +40,8 @@ public abstract class AbstractPropertyAccessor extends TypeConverterSupport impl
|
||||||
|
|
||||||
private boolean autoGrowNestedPaths = false;
|
private boolean autoGrowNestedPaths = false;
|
||||||
|
|
||||||
|
boolean suppressNotWritablePropertyException = false;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setExtractOldValueForEditor(boolean extractOldValueForEditor) {
|
public void setExtractOldValueForEditor(boolean extractOldValueForEditor) {
|
||||||
|
|
@ -89,30 +91,41 @@ public abstract class AbstractPropertyAccessor extends TypeConverterSupport impl
|
||||||
List<PropertyAccessException> propertyAccessExceptions = null;
|
List<PropertyAccessException> propertyAccessExceptions = null;
|
||||||
List<PropertyValue> propertyValues = (pvs instanceof MutablePropertyValues ?
|
List<PropertyValue> propertyValues = (pvs instanceof MutablePropertyValues ?
|
||||||
((MutablePropertyValues) pvs).getPropertyValueList() : Arrays.asList(pvs.getPropertyValues()));
|
((MutablePropertyValues) pvs).getPropertyValueList() : Arrays.asList(pvs.getPropertyValues()));
|
||||||
for (PropertyValue pv : propertyValues) {
|
|
||||||
try {
|
if (ignoreUnknown) {
|
||||||
// This method may throw any BeansException, which won't be caught
|
this.suppressNotWritablePropertyException = true;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
for (PropertyValue pv : propertyValues) {
|
||||||
|
// setPropertyValue may throw any BeansException, which won't be caught
|
||||||
// here, if there is a critical failure such as no matching field.
|
// here, if there is a critical failure such as no matching field.
|
||||||
// We can attempt to deal only with less serious exceptions.
|
// We can attempt to deal only with less serious exceptions.
|
||||||
setPropertyValue(pv);
|
try {
|
||||||
}
|
setPropertyValue(pv);
|
||||||
catch (NotWritablePropertyException ex) {
|
|
||||||
if (!ignoreUnknown) {
|
|
||||||
throw ex;
|
|
||||||
}
|
}
|
||||||
// Otherwise, just ignore it and continue...
|
catch (NotWritablePropertyException ex) {
|
||||||
}
|
if (!ignoreUnknown) {
|
||||||
catch (NullValueInNestedPathException ex) {
|
throw ex;
|
||||||
if (!ignoreInvalid) {
|
}
|
||||||
throw ex;
|
// Otherwise, just ignore it and continue...
|
||||||
}
|
}
|
||||||
// Otherwise, just ignore it and continue...
|
catch (NullValueInNestedPathException ex) {
|
||||||
}
|
if (!ignoreInvalid) {
|
||||||
catch (PropertyAccessException ex) {
|
throw ex;
|
||||||
if (propertyAccessExceptions == null) {
|
}
|
||||||
propertyAccessExceptions = new ArrayList<>();
|
// Otherwise, just ignore it and continue...
|
||||||
}
|
}
|
||||||
propertyAccessExceptions.add(ex);
|
catch (PropertyAccessException ex) {
|
||||||
|
if (propertyAccessExceptions == null) {
|
||||||
|
propertyAccessExceptions = new ArrayList<>();
|
||||||
|
}
|
||||||
|
propertyAccessExceptions.add(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (ignoreUnknown) {
|
||||||
|
this.suppressNotWritablePropertyException = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue