1
1
/*
2
- * Copyright 2012-2015 the original author or authors.
2
+ * Copyright 2012-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
15
15
*/
16
16
package org .springframework .data .mapping ;
17
17
18
- import java .util .ArrayList ;
19
18
import java .util .Arrays ;
19
+ import java .util .Collection ;
20
+ import java .util .HashSet ;
20
21
import java .util .List ;
22
+ import java .util .Set ;
21
23
22
24
import org .springframework .beans .PropertyMatches ;
23
25
import org .springframework .data .util .TypeInformation ;
@@ -38,20 +40,21 @@ public class PropertyReferenceException extends RuntimeException {
38
40
private final String propertyName ;
39
41
private final TypeInformation <?> type ;
40
42
private final List <PropertyPath > alreadyResolvedPath ;
41
- private final List <String > propertyMatches ;
43
+ private final Set <String > propertyMatches ;
42
44
43
45
/**
44
46
* Creates a new {@link PropertyReferenceException}.
45
47
*
46
- * @param propertyName the name of the property not found on the given type.
47
- * @param type the type the property could not be found on.
48
- * @param alreadyResolvedPah the previously calculated {@link PropertyPath}s.
48
+ * @param propertyName the name of the property not found on the given type, must not be {@literal null} or empty .
49
+ * @param type the type the property could not be found on, must not be {@literal null} .
50
+ * @param alreadyResolvedPah the previously calculated {@link PropertyPath}s, must not be {@literal null} .
49
51
*/
50
52
public PropertyReferenceException (String propertyName , TypeInformation <?> type ,
51
53
List <PropertyPath > alreadyResolvedPah ) {
52
54
53
- Assert .hasText (propertyName );
54
- Assert .notNull (type );
55
+ Assert .hasText (propertyName , "Property name must not be null!" );
56
+ Assert .notNull (type , "Type must not be null!" );
57
+ Assert .notNull (alreadyResolvedPah , "Already resolved paths must not be null!" );
55
58
56
59
this .propertyName = propertyName ;
57
60
this .type = type ;
@@ -71,12 +74,21 @@ public String getPropertyName() {
71
74
/**
72
75
* Returns the type the property could not be found on.
73
76
*
74
- * @return the type
77
+ * @return will never be {@literal null}.
75
78
*/
76
79
public TypeInformation <?> getType () {
77
80
return type ;
78
81
}
79
82
83
+ /**
84
+ * Returns the properties that the invalid property might have been meant to be referred to.
85
+ *
86
+ * @return will never be {@literal null}.
87
+ */
88
+ Collection <String > getPropertyMatches () {
89
+ return propertyMatches ;
90
+ }
91
+
80
92
/*
81
93
* (non-Javadoc)
82
94
* @see java.lang.Throwable#getMessage()
@@ -114,7 +126,7 @@ public PropertyPath getBaseProperty() {
114
126
* Returns whether the given {@link PropertyReferenceException} has a deeper resolution depth (i.e. a longer path of
115
127
* already resolved properties) than the current exception.
116
128
*
117
- * @param exception
129
+ * @param exception must not be {@literal null}.
118
130
* @return
119
131
*/
120
132
public boolean hasDeeperResolutionDepthThan (PropertyReferenceException exception ) {
@@ -128,9 +140,9 @@ public boolean hasDeeperResolutionDepthThan(PropertyReferenceException exception
128
140
* @param type must not be {@literal null}.
129
141
* @return
130
142
*/
131
- private static List <String > detectPotentialMatches (String propertyName , Class <?> type ) {
143
+ private static Set <String > detectPotentialMatches (String propertyName , Class <?> type ) {
132
144
133
- List <String > result = new ArrayList <String >();
145
+ Set <String > result = new HashSet <String >();
134
146
result .addAll (Arrays .asList (PropertyMatches .forField (propertyName , type ).getPossibleMatches ()));
135
147
result .addAll (Arrays .asList (PropertyMatches .forProperty (propertyName , type ).getPossibleMatches ()));
136
148
0 commit comments