|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2018 the original author or authors. |
| 2 | + * Copyright 2002-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -40,6 +40,8 @@ public abstract class AbstractPropertyAccessor extends TypeConverterSupport impl
|
40 | 40 |
|
41 | 41 | private boolean autoGrowNestedPaths = false;
|
42 | 42 |
|
| 43 | + boolean suppressNotWritablePropertyException = false; |
| 44 | + |
43 | 45 |
|
44 | 46 | @Override
|
45 | 47 | public void setExtractOldValueForEditor(boolean extractOldValueForEditor) {
|
@@ -89,30 +91,41 @@ public void setPropertyValues(PropertyValues pvs, boolean ignoreUnknown, boolean
|
89 | 91 | List<PropertyAccessException> propertyAccessExceptions = null;
|
90 | 92 | List<PropertyValue> propertyValues = (pvs instanceof MutablePropertyValues ?
|
91 | 93 | ((MutablePropertyValues) pvs).getPropertyValueList() : Arrays.asList(pvs.getPropertyValues()));
|
92 |
| - for (PropertyValue pv : propertyValues) { |
93 |
| - try { |
94 |
| - // This method may throw any BeansException, which won't be caught |
| 94 | + |
| 95 | + if (ignoreUnknown) { |
| 96 | + this.suppressNotWritablePropertyException = true; |
| 97 | + } |
| 98 | + try { |
| 99 | + for (PropertyValue pv : propertyValues) { |
| 100 | + // setPropertyValue may throw any BeansException, which won't be caught |
95 | 101 | // here, if there is a critical failure such as no matching field.
|
96 | 102 | // We can attempt to deal only with less serious exceptions.
|
97 |
| - setPropertyValue(pv); |
98 |
| - } |
99 |
| - catch (NotWritablePropertyException ex) { |
100 |
| - if (!ignoreUnknown) { |
101 |
| - throw ex; |
| 103 | + try { |
| 104 | + setPropertyValue(pv); |
102 | 105 | }
|
103 |
| - // Otherwise, just ignore it and continue... |
104 |
| - } |
105 |
| - catch (NullValueInNestedPathException ex) { |
106 |
| - if (!ignoreInvalid) { |
107 |
| - throw ex; |
| 106 | + catch (NotWritablePropertyException ex) { |
| 107 | + if (!ignoreUnknown) { |
| 108 | + throw ex; |
| 109 | + } |
| 110 | + // Otherwise, just ignore it and continue... |
108 | 111 | }
|
109 |
| - // Otherwise, just ignore it and continue... |
110 |
| - } |
111 |
| - catch (PropertyAccessException ex) { |
112 |
| - if (propertyAccessExceptions == null) { |
113 |
| - propertyAccessExceptions = new ArrayList<>(); |
| 112 | + catch (NullValueInNestedPathException ex) { |
| 113 | + if (!ignoreInvalid) { |
| 114 | + throw ex; |
| 115 | + } |
| 116 | + // Otherwise, just ignore it and continue... |
| 117 | + } |
| 118 | + catch (PropertyAccessException ex) { |
| 119 | + if (propertyAccessExceptions == null) { |
| 120 | + propertyAccessExceptions = new ArrayList<>(); |
| 121 | + } |
| 122 | + propertyAccessExceptions.add(ex); |
114 | 123 | }
|
115 |
| - propertyAccessExceptions.add(ex); |
| 124 | + } |
| 125 | + } |
| 126 | + finally { |
| 127 | + if (ignoreUnknown) { |
| 128 | + this.suppressNotWritablePropertyException = false; |
116 | 129 | }
|
117 | 130 | }
|
118 | 131 |
|
|
0 commit comments