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