Fix regression with binding and validation
Previously, the binding may have to call the getter first to retrieve the
old value of a property before actually setting it. This was guarded by
a catch block that was accidentally removed in 3d86f15
Restore that catch block and add a test to cover it.
Issue: SPR-12805
			
			
This commit is contained in:
		
							parent
							
								
									2ab34373d1
								
							
						
					
					
						commit
						6fb3190353
					
				| 
						 | 
					@ -20,6 +20,7 @@ import java.beans.PropertyChangeEvent;
 | 
				
			||||||
import java.lang.reflect.Array;
 | 
					import java.lang.reflect.Array;
 | 
				
			||||||
import java.lang.reflect.InvocationTargetException;
 | 
					import java.lang.reflect.InvocationTargetException;
 | 
				
			||||||
import java.lang.reflect.UndeclaredThrowableException;
 | 
					import java.lang.reflect.UndeclaredThrowableException;
 | 
				
			||||||
 | 
					import java.security.PrivilegedActionException;
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
import java.util.Arrays;
 | 
					import java.util.Arrays;
 | 
				
			||||||
import java.util.Collection;
 | 
					import java.util.Collection;
 | 
				
			||||||
| 
						 | 
					@ -523,7 +524,18 @@ public abstract class AbstractPropertyAccessor extends TypeConverterSupport impl
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					else {
 | 
										else {
 | 
				
			||||||
						if (isExtractOldValueForEditor() && ph.isReadable()) {
 | 
											if (isExtractOldValueForEditor() && ph.isReadable()) {
 | 
				
			||||||
							oldValue = ph.getValue();
 | 
												try {
 | 
				
			||||||
 | 
													oldValue = ph.getValue();
 | 
				
			||||||
 | 
												}
 | 
				
			||||||
 | 
												catch (Exception ex) {
 | 
				
			||||||
 | 
													if (ex instanceof PrivilegedActionException) {
 | 
				
			||||||
 | 
														ex = ((PrivilegedActionException) ex).getException();
 | 
				
			||||||
 | 
													}
 | 
				
			||||||
 | 
													if (logger.isDebugEnabled()) {
 | 
				
			||||||
 | 
														logger.debug("Could not read previous value of property '" +
 | 
				
			||||||
 | 
																this.nestedPath + propertyName + "'", ex);
 | 
				
			||||||
 | 
													}
 | 
				
			||||||
 | 
												}
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
						valueToApply = convertForProperty(
 | 
											valueToApply = convertForProperty(
 | 
				
			||||||
								propertyName, oldValue, originalValue, ph.toTypeDescriptor());
 | 
													propertyName, oldValue, originalValue, ph.toTypeDescriptor());
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,6 +51,15 @@ public final class BeanWrapperTests extends AbstractConfigurablePropertyAccessor
 | 
				
			||||||
		assertTrue("Set name to tom", target.getName().equals("tom"));
 | 
							assertTrue("Set name to tom", target.getName().equals("tom"));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Test
 | 
				
			||||||
 | 
						public void getterSilentlyFailWithOldValueExtraction() {
 | 
				
			||||||
 | 
							GetterBean target = new GetterBean();
 | 
				
			||||||
 | 
							BeanWrapper accessor = createAccessor(target);
 | 
				
			||||||
 | 
							accessor.setExtractOldValueForEditor(true); // This will call the getter
 | 
				
			||||||
 | 
							accessor.setPropertyValue("name", "tom");
 | 
				
			||||||
 | 
							assertTrue("Set name to tom", target.getName().equals("tom"));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
	public void setValidAndInvalidPropertyValuesShouldContainExceptionDetails() {
 | 
						public void setValidAndInvalidPropertyValuesShouldContainExceptionDetails() {
 | 
				
			||||||
		TestBean target = new TestBean();
 | 
							TestBean target = new TestBean();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue