1717
1818import java .io .Serial ;
1919import java .lang .reflect .Method ;
20+ import java .lang .reflect .Type ;
21+ import java .util .Arrays ;
22+ import java .util .stream .Collectors ;
2023
2124import org .jspecify .annotations .Nullable ;
2225
3134public final class QueryCreationException extends RepositoryCreationException {
3235
3336 private static final @ Serial long serialVersionUID = -1238456123580L ;
34- private static final String MESSAGE_TEMPLATE = "Could not create query for method [%s]; Could not find property '%s' on domain class '%s'" ;
3537
3638 private final Method method ;
3739
@@ -81,7 +83,8 @@ private QueryCreationException(@Nullable String message, @Nullable Throwable cau
8183 public static QueryCreationException invalidProperty (QueryMethod method , String propertyName ) {
8284
8385 return new QueryCreationException (
84- String .format (MESSAGE_TEMPLATE , method , propertyName , method .getDomainClass ().getName ()), method );
86+ "Could not find property '%s' on domain class '%s'" .formatted (propertyName , method .getDomainClass ().getName ()),
87+ method );
8588 }
8689
8790 /**
@@ -92,7 +95,7 @@ public static QueryCreationException invalidProperty(QueryMethod method, String
9295 * @return the {@link QueryCreationException}.
9396 */
9497 public static QueryCreationException create (QueryMethod method , String message ) {
95- return new QueryCreationException (createMessage ( message , method . getMethod ()) , method );
98+ return new QueryCreationException (message , method );
9699 }
97100
98101 /**
@@ -134,13 +137,10 @@ public static QueryCreationException create(QueryMethod method, String message,
134137 */
135138 public static QueryCreationException create (@ Nullable String message , @ Nullable Throwable cause ,
136139 Class <?> repositoryInterface , Method method ) {
137- return new QueryCreationException (createMessage ( message , method ) ,
140+ return new QueryCreationException (message ,
138141 cause , repositoryInterface , method );
139142 }
140143
141- private static String createMessage (@ Nullable String message , Method method ) {
142- return String .format ("Could not create query for [%s]; Reason: %s" , method , message );
143- }
144144
145145 /**
146146 * @return the method causing the exception.
@@ -150,4 +150,19 @@ public Method getMethod() {
150150 return method ;
151151 }
152152
153+ @ Override
154+ public String getLocalizedMessage () {
155+
156+ StringBuilder sb = new StringBuilder ();
157+ sb .append (method .getDeclaringClass ().getSimpleName ()).append ('.' );
158+ sb .append (method .getName ());
159+
160+ sb .append (method .getName ());
161+ sb .append (Arrays .stream (method .getParameterTypes ()) //
162+ .map (Type ::getTypeName ) //
163+ .collect (Collectors .joining ("," , "(" , ")" )));
164+
165+ return "Cannot create query for method [%s]; %s" .formatted (sb .toString (), getMessage ());
166+ }
167+
153168}
0 commit comments