@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()).append("; nested PropertyAccessExceptions ("); sb.append(getExceptionCount()).append(") are:"); for (int i = 0; i < this.propertyAccessExceptions.length; i++) { sb.append('\n').append("PropertyAccessException ").append(i + 1).append(": "); sb.append(this.propertyAccessExceptions[i]); } return sb.toString(); }
throw new PropertyBatchUpdateException(paeArray);
public void xtestTypeMismatch() { try { getBeanFactory().getBean("typeMismatch"); fail("Shouldn't succeed with type mismatch"); } catch (BeanCreationException wex) { assertEquals("typeMismatch", wex.getBeanName()); assertTrue(wex.getCause() instanceof PropertyBatchUpdateException); PropertyBatchUpdateException ex = (PropertyBatchUpdateException) wex.getCause(); // Further tests assertTrue("Has one error ", ex.getExceptionCount() == 1); assertTrue("Error is for field age", ex.getPropertyAccessException("age") != null); assertTrue("We have rejected age in exception", ex.getPropertyAccessException("age").getPropertyChangeEvent().getNewValue().equals("34x")); } }
/** * Apply given property values to the target object. * <p>Default implementation applies all of the supplied property * values as bean property values. By default, unknown fields will * be ignored. * @param mpvs the property values to be bound (can be modified) * @see #getTarget * @see #getPropertyAccessor * @see #isIgnoreUnknownFields * @see #getBindingErrorProcessor * @see BindingErrorProcessor#processPropertyAccessException */ protected void applyPropertyValues(MutablePropertyValues mpvs) { try { // Bind request parameters onto target object. getPropertyAccessor().setPropertyValues(mpvs, isIgnoreUnknownFields(), isIgnoreInvalidFields()); } catch (PropertyBatchUpdateException ex) { // Use bind error processor to create FieldErrors. for (PropertyAccessException pae : ex.getPropertyAccessExceptions()) { getBindingErrorProcessor().processPropertyAccessException(pae, getInternalBindingResult()); } } }
PropertyAccessException pae = ex.getPropertyAccessException("map[key2]"); assertTrue(pae instanceof TypeMismatchException);
@Test public void setValidAndInvalidPropertyValuesShouldContainExceptionDetails() { TestBean target = new TestBean(); String newName = "tony"; String invalidTouchy = ".valid"; try { BeanWrapper accessor = createAccessor(target); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValue(new PropertyValue("age", "foobar")); pvs.addPropertyValue(new PropertyValue("name", newName)); pvs.addPropertyValue(new PropertyValue("touchy", invalidTouchy)); accessor.setPropertyValues(pvs); fail("Should throw exception when everything is valid"); } catch (PropertyBatchUpdateException ex) { assertTrue("Must contain 2 exceptions", ex.getExceptionCount() == 2); // Test validly set property matches assertTrue("Valid set property must stick", target.getName().equals(newName)); assertTrue("Invalid set property must retain old value", target.getAge() == 0); assertTrue("New value of dodgy setter must be available through exception", ex.getPropertyAccessException("touchy").getPropertyChangeEvent().getNewValue().equals(invalidTouchy)); } }
/** * Apply given property values to the target object. * <p>Default implementation applies all of the supplied property * values as bean property values. By default, unknown fields will * be ignored. * @param mpvs the property values to be bound (can be modified) * @see #getTarget * @see #getPropertyAccessor * @see #isIgnoreUnknownFields * @see #getBindingErrorProcessor * @see BindingErrorProcessor#processPropertyAccessException */ protected void applyPropertyValues(MutablePropertyValues mpvs) { try { // Bind request parameters onto target object. getPropertyAccessor().setPropertyValues(mpvs, isIgnoreUnknownFields(), isIgnoreInvalidFields()); } catch (PropertyBatchUpdateException ex) { // Use bind error processor to create FieldErrors. for (PropertyAccessException pae : ex.getPropertyAccessExceptions()) { getBindingErrorProcessor().processPropertyAccessException(pae, getInternalBindingResult()); } } }
@Override public void printStackTrace(PrintStream ps) { synchronized (ps) { ps.println(getClass().getName() + "; nested PropertyAccessException details (" + getExceptionCount() + ") are:"); for (int i = 0; i < this.propertyAccessExceptions.length; i++) { ps.println("PropertyAccessException " + (i + 1) + ":"); this.propertyAccessExceptions[i].printStackTrace(ps); } } }
throw new PropertyBatchUpdateException(paeArray);
/** * Apply given property values to the target object. * <p>Default implementation applies all of the supplied property * values as bean property values. By default, unknown fields will * be ignored. * @param mpvs the property values to be bound (can be modified) * @see #getTarget * @see #getPropertyAccessor * @see #isIgnoreUnknownFields * @see #getBindingErrorProcessor * @see BindingErrorProcessor#processPropertyAccessException */ protected void applyPropertyValues(MutablePropertyValues mpvs) { try { // Bind request parameters onto target object. getPropertyAccessor().setPropertyValues(mpvs, isIgnoreUnknownFields(), isIgnoreInvalidFields()); } catch (PropertyBatchUpdateException ex) { // Use bind error processor to create FieldErrors. for (PropertyAccessException pae : ex.getPropertyAccessExceptions()) { getBindingErrorProcessor().processPropertyAccessException(pae, getInternalBindingResult()); } } }
@Override public void printStackTrace(PrintWriter pw) { synchronized (pw) { pw.println(getClass().getName() + "; nested PropertyAccessException details (" + getExceptionCount() + ") are:"); for (int i = 0; i < this.propertyAccessExceptions.length; i++) { pw.println("PropertyAccessException " + (i + 1) + ":"); this.propertyAccessExceptions[i].printStackTrace(pw); } } }
PropertyAccessException[] paeArray = propertyAccessExceptions.toArray(new PropertyAccessException[propertyAccessExceptions.size()]); throw new PropertyBatchUpdateException(paeArray);
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()).append("; nested PropertyAccessExceptions ("); sb.append(getExceptionCount()).append(") are:"); for (int i = 0; i < this.propertyAccessExceptions.length; i++) { sb.append('\n').append("PropertyAccessException ").append(i + 1).append(": "); sb.append(this.propertyAccessExceptions[i]); } return sb.toString(); }
PropertyAccessException[] paeArray = propertyAccessExceptions.toArray(new PropertyAccessException[propertyAccessExceptions.size()]); throw new PropertyBatchUpdateException(paeArray);
@Override public void printStackTrace(PrintWriter pw) { synchronized (pw) { pw.println(getClass().getName() + "; nested PropertyAccessException details (" + getExceptionCount() + ") are:"); for (int i = 0; i < this.propertyAccessExceptions.length; i++) { pw.println("PropertyAccessException " + (i + 1) + ":"); this.propertyAccessExceptions[i].printStackTrace(pw); } } }
@Override public void printStackTrace(PrintStream ps) { synchronized (ps) { ps.println(getClass().getName() + "; nested PropertyAccessException details (" + getExceptionCount() + ") are:"); for (int i = 0; i < this.propertyAccessExceptions.length; i++) { ps.println("PropertyAccessException " + (i + 1) + ":"); this.propertyAccessExceptions[i].printStackTrace(ps); } } }
@Override public void printStackTrace(PrintWriter pw) { synchronized (pw) { pw.println(getClass().getName() + "; nested PropertyAccessException details (" + getExceptionCount() + ") are:"); for (int i = 0; i < this.propertyAccessExceptions.length; i++) { pw.println("PropertyAccessException " + (i + 1) + ":"); this.propertyAccessExceptions[i].printStackTrace(pw); } } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()).append("; nested PropertyAccessExceptions ("); sb.append(getExceptionCount()).append(") are:"); for (int i = 0; i < this.propertyAccessExceptions.length; i++) { sb.append('\n').append("PropertyAccessException ").append(i + 1).append(": "); sb.append(this.propertyAccessExceptions[i]); } return sb.toString(); }
@Override public void printStackTrace(PrintStream ps) { synchronized (ps) { ps.println(getClass().getName() + "; nested PropertyAccessException details (" + getExceptionCount() + ") are:"); for (int i = 0; i < this.propertyAccessExceptions.length; i++) { ps.println("PropertyAccessException " + (i + 1) + ":"); this.propertyAccessExceptions[i].printStackTrace(ps); } } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()).append("; nested PropertyAccessExceptions ("); sb.append(getExceptionCount()).append(") are:"); for (int i = 0; i < this.propertyAccessExceptions.length; i++) { sb.append('\n').append("PropertyAccessException ").append(i + 1).append(": "); sb.append(this.propertyAccessExceptions[i]); } return sb.toString(); }