Skip to content

Commit 64b10a0

Browse files
christophstroblmp911de
authored andcommitted
DATACMNS-1721 - Lazily evaluate potential property matches in PropertyReferenceException.
Original pull request: #443.
1 parent 061f542 commit 64b10a0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/main/java/org/springframework/data/mapping/PropertyReferenceException.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Set;
2323

2424
import org.springframework.beans.PropertyMatches;
25+
import org.springframework.data.util.Lazy;
2526
import org.springframework.data.util.TypeInformation;
2627
import org.springframework.lang.Nullable;
2728
import org.springframework.util.Assert;
@@ -31,6 +32,7 @@
3132
* Exception being thrown when creating {@link PropertyPath} instances.
3233
*
3334
* @author Oliver Gierke
35+
* @author Christoph Strobl
3436
*/
3537
public class PropertyReferenceException extends RuntimeException {
3638

@@ -41,7 +43,7 @@ public class PropertyReferenceException extends RuntimeException {
4143
private final String propertyName;
4244
private final TypeInformation<?> type;
4345
private final List<PropertyPath> alreadyResolvedPath;
44-
private final Set<String> propertyMatches;
46+
private final Lazy<Set<String>> propertyMatches;
4547

4648
/**
4749
* Creates a new {@link PropertyReferenceException}.
@@ -60,7 +62,7 @@ public PropertyReferenceException(String propertyName, TypeInformation<?> type,
6062
this.propertyName = propertyName;
6163
this.type = type;
6264
this.alreadyResolvedPath = alreadyResolvedPah;
63-
this.propertyMatches = detectPotentialMatches(propertyName, type.getType());
65+
this.propertyMatches = Lazy.of(() -> detectPotentialMatches(propertyName, type.getType()));
6466
}
6567

6668
/**
@@ -87,7 +89,7 @@ public TypeInformation<?> getType() {
8789
* @return will never be {@literal null}.
8890
*/
8991
Collection<String> getPropertyMatches() {
90-
return propertyMatches;
92+
return propertyMatches.get();
9193
}
9294

9395
/*
@@ -100,8 +102,9 @@ public String getMessage() {
100102
StringBuilder builder = new StringBuilder(
101103
String.format(ERROR_TEMPLATE, propertyName, type.getType().getSimpleName()));
102104

103-
if (!propertyMatches.isEmpty()) {
104-
String matches = StringUtils.collectionToDelimitedString(propertyMatches, ",", "'", "'");
105+
Collection<String> potentialMatches = getPropertyMatches();
106+
if (!potentialMatches.isEmpty()) {
107+
String matches = StringUtils.collectionToDelimitedString(potentialMatches, ",", "'", "'");
105108
builder.append(String.format(HINTS_TEMPLATE, matches));
106109
}
107110

0 commit comments

Comments
 (0)