DATACMNS-804 - ParametersParameterAccessor now correctly iterates over only the bindable values.

Corrected the way the BindableParametersIterator works by limiting the upper bound of the iteration to the number of actually bindable parameters.
This commit is contained in:
Oliver Gierke
2016-01-21 10:19:59 +01:00
parent b17a797fe6
commit 85e569b4f6
2 changed files with 38 additions and 6 deletions

View File

@@ -145,7 +145,7 @@ public class ParametersParameterAccessor implements ParameterAccessor {
* @see org.springframework.data.repository.query.ParameterAccessor#iterator()
*/
public BindableParameterIterator iterator() {
return new BindableParameterIterator();
return new BindableParameterIterator(this);
}
/**
@@ -153,17 +153,33 @@ public class ParametersParameterAccessor implements ParameterAccessor {
*
* @author Oliver Gierke
*/
private class BindableParameterIterator implements Iterator<Object> {
private static class BindableParameterIterator implements Iterator<Object> {
private final int bindableParameterCount;
private final ParameterAccessor accessor;
private int currentIndex = 0;
/**
* Creates a new {@link BindableParameterIterator}.
*
* @param accessor must not be {@literal null}.
*/
public BindableParameterIterator(ParametersParameterAccessor accessor) {
Assert.notNull(accessor, "ParametersParameterAccessor must not be null!");
this.accessor = accessor;
this.bindableParameterCount = accessor.getParameters().getBindableParameters().getNumberOfParameters();
}
/**
* Returns the next bindable parameter.
*
* @return
*/
public Object next() {
return getBindableValue(currentIndex++);
return accessor.getBindableValue(currentIndex++);
}
/*
@@ -171,7 +187,7 @@ public class ParametersParameterAccessor implements ParameterAccessor {
* @see java.util.Iterator#hasNext()
*/
public boolean hasNext() {
return values.size() > currentIndex;
return bindableParameterCount > currentIndex;
}
/*