Skip to content

Commit 01563eb

Browse files
committed
DATACMNS-791 - Improved messages in QueryMethodeParameterConversionException and ReflectionRepositoryInvoker.
1 parent b0f81ef commit 01563eb

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/main/java/org/springframework/data/repository/support/QueryMethodParameterConversionException.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@ public class QueryMethodParameterConversionException extends RuntimeException {
3434
private final MethodParameter parameter;
3535

3636
/**
37+
* Creates a new {@link QueryMethodParameterConversionException} for the given source object, {@link MethodParameter}
38+
* and root cause {@link ConversionException}.
39+
*
3740
* @param source can be {@literal null}.
3841
* @param parameter the {@link MethodParameter} the value should've been converted for, must not be {@literal null}..
3942
* @param cause the original {@link ConversionException}, must not be {@literal null}.
4043
*/
4144
public QueryMethodParameterConversionException(Object source, MethodParameter parameter, ConversionException cause) {
4245

43-
super("message", cause);
46+
super(String.format("Failed to convert %s into %s!", source, parameter.getParameterType().getName()), cause);
4447

4548
Assert.notNull(parameter, "Method parameter must not be null!");
4649
Assert.notNull(cause, "ConversionException must not be null!");

src/main/java/org/springframework/data/repository/support/ReflectionRepositoryInvoker.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2014 the original author or authors.
2+
* Copyright 2013-2015 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.
@@ -32,6 +32,7 @@
3232
import org.springframework.data.repository.core.RepositoryMetadata;
3333
import org.springframework.data.repository.query.Param;
3434
import org.springframework.util.Assert;
35+
import org.springframework.util.ClassUtils;
3536
import org.springframework.util.LinkedMultiValueMap;
3637
import org.springframework.util.MultiValueMap;
3738
import org.springframework.util.ReflectionUtils;
@@ -46,6 +47,7 @@
4647
class ReflectionRepositoryInvoker implements RepositoryInvoker {
4748

4849
private static final AnnotationAttribute PARAM_ANNOTATION = new AnnotationAttribute(Param.class);
50+
private static final String NAME_NOT_FOUND = "Unable to detect parameter names for query method %s! Use @Param or compile with -parameters on JDK 8.";
4951

5052
private final Object repository;
5153
private final CrudMethods methods;
@@ -60,7 +62,8 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker {
6062
* @param metadata must not be {@literal null}.
6163
* @param conversionService must not be {@literal null}.
6264
*/
63-
public ReflectionRepositoryInvoker(Object repository, RepositoryMetadata metadata, ConversionService conversionService) {
65+
public ReflectionRepositoryInvoker(Object repository, RepositoryMetadata metadata,
66+
ConversionService conversionService) {
6467

6568
Assert.notNull(repository, "Repository must not be null!");
6669
Assert.notNull(metadata, "RepositoryMetadata must not be null!");
@@ -229,8 +232,7 @@ private Object[] prepareParameters(Method method, MultiValueMap<String, ? extend
229232
String parameterName = param.getParameterName();
230233

231234
if (!StringUtils.hasText(parameterName)) {
232-
throw new IllegalArgumentException("No @Param annotation found on query method " + method.getName()
233-
+ " for parameter " + parameterName);
235+
throw new IllegalArgumentException(String.format(NAME_NOT_FOUND, ClassUtils.getQualifiedMethodName(method)));
234236
}
235237

236238
Object value = unwrapSingleElement(rawParameters.get(parameterName));

0 commit comments

Comments
 (0)