22
22
import java .util .Set ;
23
23
24
24
import org .springframework .beans .PropertyMatches ;
25
+ import org .springframework .data .util .Lazy ;
25
26
import org .springframework .data .util .TypeInformation ;
26
27
import org .springframework .lang .Nullable ;
27
28
import org .springframework .util .Assert ;
31
32
* Exception being thrown when creating {@link PropertyPath} instances.
32
33
*
33
34
* @author Oliver Gierke
35
+ * @author Christoph Strobl
34
36
*/
35
37
public class PropertyReferenceException extends RuntimeException {
36
38
@@ -41,7 +43,7 @@ public class PropertyReferenceException extends RuntimeException {
41
43
private final String propertyName ;
42
44
private final TypeInformation <?> type ;
43
45
private final List <PropertyPath > alreadyResolvedPath ;
44
- private final Set <String > propertyMatches ;
46
+ private final Lazy < Set <String > > propertyMatches ;
45
47
46
48
/**
47
49
* Creates a new {@link PropertyReferenceException}.
@@ -60,7 +62,7 @@ public PropertyReferenceException(String propertyName, TypeInformation<?> type,
60
62
this .propertyName = propertyName ;
61
63
this .type = type ;
62
64
this .alreadyResolvedPath = alreadyResolvedPah ;
63
- this .propertyMatches = detectPotentialMatches (propertyName , type .getType ());
65
+ this .propertyMatches = Lazy . of (() -> detectPotentialMatches (propertyName , type .getType () ));
64
66
}
65
67
66
68
/**
@@ -87,7 +89,7 @@ public TypeInformation<?> getType() {
87
89
* @return will never be {@literal null}.
88
90
*/
89
91
Collection <String > getPropertyMatches () {
90
- return propertyMatches ;
92
+ return propertyMatches . get () ;
91
93
}
92
94
93
95
/*
@@ -100,8 +102,9 @@ public String getMessage() {
100
102
StringBuilder builder = new StringBuilder (
101
103
String .format (ERROR_TEMPLATE , propertyName , type .getType ().getSimpleName ()));
102
104
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 , "," , "'" , "'" );
105
108
builder .append (String .format (HINTS_TEMPLATE , matches ));
106
109
}
107
110
0 commit comments