Skip to content

Commit 9926b68

Browse files
committed
Avoid String concatenation for not-null assertion in BeanProperty/DirectFieldBindingResult
Issue: SPR-16455 (cherry picked from commit 9c069f6)
1 parent d8a2672 commit 9926b68

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

spring-context/src/main/java/org/springframework/validation/BeanPropertyBindingResult.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
2121
import org.springframework.beans.BeanWrapper;
2222
import org.springframework.beans.ConfigurablePropertyAccessor;
2323
import org.springframework.beans.PropertyAccessorFactory;
24-
import org.springframework.util.Assert;
2524

2625
/**
2726
* Default implementation of the {@link Errors} and {@link BindingResult}
@@ -102,7 +101,9 @@ public final ConfigurablePropertyAccessor getPropertyAccessor() {
102101
* @see #getTarget()
103102
*/
104103
protected BeanWrapper createBeanWrapper() {
105-
Assert.state(this.target != null, "Cannot access properties on null bean instance '" + getObjectName() + "'!");
104+
if (this.target == null) {
105+
throw new IllegalStateException("Cannot access properties on null bean instance '" + getObjectName() + "'");
106+
}
106107
return PropertyAccessorFactory.forBeanPropertyAccess(this.target);
107108
}
108109

spring-context/src/main/java/org/springframework/validation/DirectFieldBindingResult.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@
1818

1919
import org.springframework.beans.ConfigurablePropertyAccessor;
2020
import org.springframework.beans.PropertyAccessorFactory;
21-
import org.springframework.util.Assert;
2221

2322
/**
2423
* Special implementation of the Errors and BindingResult interfaces,
@@ -90,7 +89,9 @@ public final ConfigurablePropertyAccessor getPropertyAccessor() {
9089
* @see #getTarget()
9190
*/
9291
protected ConfigurablePropertyAccessor createDirectFieldAccessor() {
93-
Assert.state(this.target != null, "Cannot access fields on null target instance '" + getObjectName() + "'!");
92+
if (this.target == null) {
93+
throw new IllegalStateException("Cannot access fields on null target instance '" + getObjectName() + "'");
94+
}
9495
return PropertyAccessorFactory.forDirectFieldAccess(this.target);
9596
}
9697

0 commit comments

Comments
 (0)