From 9c069f6cb1a58ea0861200e2a70fda6dde0ce70a Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 2 Feb 2018 11:33:39 +0100 Subject: [PATCH] Avoid String concatenation for not-null assertion in BeanProperty/DirectFieldBindingResult Issue: SPR-16455 --- .../validation/BeanPropertyBindingResult.java | 7 ++++--- .../validation/DirectFieldBindingResult.java | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/validation/BeanPropertyBindingResult.java b/spring-context/src/main/java/org/springframework/validation/BeanPropertyBindingResult.java index a9264f693f4..ccef9bdaa69 100644 --- a/spring-context/src/main/java/org/springframework/validation/BeanPropertyBindingResult.java +++ b/spring-context/src/main/java/org/springframework/validation/BeanPropertyBindingResult.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ import org.springframework.beans.BeanWrapper; import org.springframework.beans.ConfigurablePropertyAccessor; import org.springframework.beans.PropertyAccessorFactory; import org.springframework.lang.Nullable; -import org.springframework.util.Assert; /** * Default implementation of the {@link Errors} and {@link BindingResult} @@ -108,7 +107,9 @@ public class BeanPropertyBindingResult extends AbstractPropertyBindingResult imp * @see #getTarget() */ protected BeanWrapper createBeanWrapper() { - Assert.state(this.target != null, "Cannot access properties on null bean instance '" + getObjectName() + "'!"); + if (this.target == null) { + throw new IllegalStateException("Cannot access properties on null bean instance '" + getObjectName() + "'"); + } return PropertyAccessorFactory.forBeanPropertyAccess(this.target); } diff --git a/spring-context/src/main/java/org/springframework/validation/DirectFieldBindingResult.java b/spring-context/src/main/java/org/springframework/validation/DirectFieldBindingResult.java index dc49142e0a2..a28c8d04069 100644 --- a/spring-context/src/main/java/org/springframework/validation/DirectFieldBindingResult.java +++ b/spring-context/src/main/java/org/springframework/validation/DirectFieldBindingResult.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ package org.springframework.validation; import org.springframework.beans.ConfigurablePropertyAccessor; import org.springframework.beans.PropertyAccessorFactory; import org.springframework.lang.Nullable; -import org.springframework.util.Assert; /** * Special implementation of the Errors and BindingResult interfaces, @@ -94,7 +93,9 @@ public class DirectFieldBindingResult extends AbstractPropertyBindingResult { * @see #getTarget() */ protected ConfigurablePropertyAccessor createDirectFieldAccessor() { - Assert.state(this.target != null, "Cannot access fields on null target instance '" + getObjectName() + "'!"); + if (this.target == null) { + throw new IllegalStateException("Cannot access fields on null target instance '" + getObjectName() + "'"); + } return PropertyAccessorFactory.forDirectFieldAccess(this.target); }