From 8969a55c278d5f53487bbae2051cfaff24f4123a Mon Sep 17 00:00:00 2001 From: heowc Date: Mon, 13 Dec 2021 10:21:33 +0100 Subject: [PATCH] Add @Nullable to ParametersParameterAccessor.getValue(). Add missing Override and Nullable annotations. Update Javadoc to mention correct return value. Closes #2506 --- .../data/repository/query/ParameterAccessor.java | 6 ++++-- .../repository/query/ParametersParameterAccessor.java | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/data/repository/query/ParameterAccessor.java b/src/main/java/org/springframework/data/repository/query/ParameterAccessor.java index 444d61f476..b4bd87a62c 100644 --- a/src/main/java/org/springframework/data/repository/query/ParameterAccessor.java +++ b/src/main/java/org/springframework/data/repository/query/ParameterAccessor.java @@ -31,7 +31,7 @@ public interface ParameterAccessor extends Iterable { /** - * Returns the {@link Pageable} of the parameters, if available. Returns {@code null} otherwise. + * Returns the {@link Pageable} of the parameters, if available. Returns {@link Pageable#unpaged()} otherwise. * * @return */ @@ -39,7 +39,8 @@ public interface ParameterAccessor extends Iterable { /** * Returns the sort instance to be used for query creation. Will use a {@link Sort} parameter if available or the - * {@link Sort} contained in a {@link Pageable} if available. Returns {@code null} if no {@link Sort} can be found. + * {@link Sort} contained in a {@link Pageable} if available. Returns {@link Sort#unsorted()} if no {@link Sort} can + * be found. * * @return */ @@ -72,6 +73,7 @@ public interface ParameterAccessor extends Iterable { * @param index * @return */ + @Nullable Object getBindableValue(int index); /** diff --git a/src/main/java/org/springframework/data/repository/query/ParametersParameterAccessor.java b/src/main/java/org/springframework/data/repository/query/ParametersParameterAccessor.java index d447e0c320..98f04fb9ab 100644 --- a/src/main/java/org/springframework/data/repository/query/ParametersParameterAccessor.java +++ b/src/main/java/org/springframework/data/repository/query/ParametersParameterAccessor.java @@ -96,6 +96,7 @@ protected Object[] getValues() { * (non-Javadoc) * @see org.springframework.data.repository.query.ParameterAccessor#getPageable() */ + @Override public Pageable getPageable() { if (!parameters.hasPageableParameter()) { @@ -111,6 +112,7 @@ public Pageable getPageable() { * (non-Javadoc) * @see org.springframework.data.repository.query.ParameterAccessor#getSort() */ + @Override public Sort getSort() { if (parameters.hasSortParameter()) { @@ -158,6 +160,7 @@ public Class findDynamicProjection() { * @return */ @SuppressWarnings("unchecked") + @Nullable protected T getValue(int index) { return (T) values[index]; } @@ -166,6 +169,7 @@ protected T getValue(int index) { * (non-Javadoc) * @see org.springframework.data.repository.query.ParameterAccessor#getBindableValue(int) */ + @Override public Object getBindableValue(int index) { return values[parameters.getBindableParameter(index).getIndex()]; } @@ -174,6 +178,7 @@ public Object getBindableValue(int index) { * (non-Javadoc) * @see org.springframework.data.repository.query.ParameterAccessor#hasBindableNullValue() */ + @Override public boolean hasBindableNullValue() { for (Parameter parameter : parameters.getBindableParameters()) { @@ -189,6 +194,7 @@ public boolean hasBindableNullValue() { * (non-Javadoc) * @see org.springframework.data.repository.query.ParameterAccessor#iterator() */ + @Override public BindableParameterIterator iterator() { return new BindableParameterIterator(this); } @@ -223,6 +229,8 @@ public BindableParameterIterator(ParametersParameterAccessor accessor) { * * @return */ + @Nullable + @Override public Object next() { return accessor.getBindableValue(currentIndex++); } @@ -231,6 +239,7 @@ public Object next() { * (non-Javadoc) * @see java.util.Iterator#hasNext() */ + @Override public boolean hasNext() { return bindableParameterCount > currentIndex; } @@ -239,6 +248,7 @@ public boolean hasNext() { * (non-Javadoc) * @see java.util.Iterator#remove() */ + @Override public void remove() { throw new UnsupportedOperationException(); }