Skip to content

Commit f6142e1

Browse files
committed
Remove superfluous @NonNull annotations.
Closes #2976
1 parent 15298b1 commit f6142e1

8 files changed

+132
-149
lines changed

src/main/java/org/springframework/data/convert/CustomConversions.java

Lines changed: 89 additions & 96 deletions
Large diffs are not rendered by default.

src/main/java/org/springframework/data/convert/PropertyValueConversionService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.springframework.data.convert;
1717

1818
import org.springframework.data.mapping.PersistentProperty;
19-
import org.springframework.lang.NonNull;
2019
import org.springframework.lang.Nullable;
2120
import org.springframework.util.Assert;
2221

@@ -42,7 +41,7 @@ public class PropertyValueConversionService {
4241
* @throws IllegalArgumentException if {@link CustomConversions} is {@literal null}.
4342
* @see CustomConversions
4443
*/
45-
public PropertyValueConversionService(@NonNull CustomConversions conversions) {
44+
public PropertyValueConversionService(CustomConversions conversions) {
4645

4746
Assert.notNull(conversions, "CustomConversions must not be null");
4847

src/main/java/org/springframework/data/convert/PropertyValueConverter.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.util.function.BiFunction;
1919

2020
import org.springframework.data.mapping.PersistentProperty;
21-
import org.springframework.lang.NonNull;
2221
import org.springframework.lang.Nullable;
2322

2423
/**
@@ -48,8 +47,8 @@ public interface PropertyValueConverter<DV, SV, C extends ValueConversionContext
4847
* operation.
4948
*
5049
* @param value value to read.
51-
* @param context {@link ValueConversionContext} containing store-specific metadata
52-
* used in the value conversion; never {@literal null}.
50+
* @param context {@link ValueConversionContext} containing store-specific metadata used in the value conversion;
51+
* never {@literal null}.
5352
* @return the converted value. Can be {@literal null}.
5453
*/
5554
@Nullable
@@ -59,8 +58,8 @@ public interface PropertyValueConverter<DV, SV, C extends ValueConversionContext
5958
* Convert the given {@code null} value from the store into its domain value representation. Typically, a
6059
* {@literal read} operation. Returns {@code null} by default.
6160
*
62-
* @param context {@link ValueConversionContext} containing store-specific metadata
63-
* used in the value conversion; never {@literal null}.
61+
* @param context {@link ValueConversionContext} containing store-specific metadata used in the value conversion;
62+
* never {@literal null}.
6463
* @return the converted value. Can be {@literal null}.
6564
*/
6665
@Nullable
@@ -73,8 +72,8 @@ default DV readNull(C context) {
7372
* operation.
7473
*
7574
* @param value value to write; can be {@literal null}.
76-
* @param context {@link ValueConversionContext} containing store-specific metadata
77-
* used in the value conversion; never {@literal null}.
75+
* @param context {@link ValueConversionContext} containing store-specific metadata used in the value conversion;
76+
* never {@literal null}.
7877
* @return the converted value. Can be {@literal null}.
7978
*/
8079
@Nullable
@@ -84,8 +83,8 @@ default DV readNull(C context) {
8483
* Convert the given {@code null} value from the domain model into it's native store representation. Typically, a
8584
* {@literal write} operation. Returns {@code null} by default.
8685
*
87-
* @param context {@link ValueConversionContext} containing store-specific metadata
88-
* used in the value conversion; never {@literal null}.
86+
* @param context {@link ValueConversionContext} containing store-specific metadata used in the value conversion;
87+
* never {@literal null}.
8988
* @return the converted value. Can be {@literal null}.
9089
*/
9190
@Nullable
@@ -127,32 +126,32 @@ class FunctionPropertyValueConverter<DV, SV, P extends PersistentProperty<P>>
127126
private final BiFunction<DV, ValueConversionContext<P>, SV> writer;
128127
private final BiFunction<SV, ValueConversionContext<P>, DV> reader;
129128

130-
public FunctionPropertyValueConverter(@NonNull BiFunction<DV, ValueConversionContext<P>, SV> writer,
131-
@NonNull BiFunction<SV, ValueConversionContext<P>, DV> reader) {
129+
public FunctionPropertyValueConverter(BiFunction<DV, ValueConversionContext<P>, SV> writer,
130+
BiFunction<SV, ValueConversionContext<P>, DV> reader) {
132131

133132
this.writer = writer;
134133
this.reader = reader;
135134
}
136135

137136
@Nullable
138137
@Override
139-
public SV write(@Nullable DV value, @NonNull ValueConversionContext<P> context) {
138+
public SV write(@Nullable DV value, ValueConversionContext<P> context) {
140139
return writer.apply(value, context);
141140
}
142141

143142
@Override
144-
public SV writeNull(@NonNull ValueConversionContext<P> context) {
143+
public SV writeNull(ValueConversionContext<P> context) {
145144
return writer.apply(null, context);
146145
}
147146

148147
@Nullable
149148
@Override
150-
public DV read(@Nullable SV value, @NonNull ValueConversionContext<P> context) {
149+
public DV read(@Nullable SV value, ValueConversionContext<P> context) {
151150
return reader.apply(value, context);
152151
}
153152

154153
@Override
155-
public DV readNull(@NonNull ValueConversionContext<P> context) {
154+
public DV readNull(ValueConversionContext<P> context) {
156155
return reader.apply(null, context);
157156
}
158157
}

src/main/java/org/springframework/data/convert/PropertyValueConverterFactories.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,12 @@ static class Cache {
215215
Map<PersistentProperty<?>, Optional<PropertyValueConverter<?, ?, ? extends ValueConversionContext<?>>>> perPropertyCache = new ConcurrentHashMap<>();
216216
Map<Class<?>, Optional<PropertyValueConverter<?, ?, ? extends ValueConversionContext<?>>>> typeCache = new ConcurrentHashMap<>();
217217

218+
@Nullable
218219
Optional<PropertyValueConverter<?, ?, ? extends ValueConversionContext<?>>> get(PersistentProperty<?> property) {
219220
return perPropertyCache.get(property);
220221
}
221222

223+
@Nullable
222224
Optional<PropertyValueConverter<?, ?, ? extends ValueConversionContext<?>>> get(Class<?> type) {
223225
return typeCache.get(type);
224226
}

src/main/java/org/springframework/data/convert/PropertyValueConverterRegistrar.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.springframework.data.convert.PropertyValueConverter.FunctionPropertyValueConverter;
2323
import org.springframework.data.mapping.PersistentProperty;
2424
import org.springframework.data.util.MethodInvocationRecorder;
25-
import org.springframework.lang.NonNull;
2625
import org.springframework.util.Assert;
2726

2827
/**
@@ -106,7 +105,7 @@ public PropertyValueConverterRegistrar<P> registerConverter(Class<?> type, Strin
106105
* @throws IllegalArgumentException if the {@link ValueConverterRegistry} is {@literal null}.
107106
* @see ValueConverterRegistry
108107
*/
109-
public void registerConvertersIn(@NonNull ValueConverterRegistry<P> target) {
108+
public void registerConvertersIn(ValueConverterRegistry<P> target) {
110109

111110
Assert.notNull(target, "Target registry must not be null");
112111

@@ -119,7 +118,7 @@ public void registerConvertersIn(@NonNull ValueConverterRegistry<P> target) {
119118
*
120119
* @return new instance of {@link SimplePropertyValueConverterRegistry}.
121120
*/
122-
@NonNull
121+
123122
public ValueConverterRegistry<P> buildRegistry() {
124123
return new SimplePropertyValueConverterRegistry<>(registry);
125124
}
@@ -135,7 +134,7 @@ public static class WritingConverterRegistrationBuilder<T, S, P extends Persiste
135134
private final PropertyValueConverterRegistrar<P> config;
136135

137136
WritingConverterRegistrationBuilder(Class<T> type, String property,
138-
@NonNull PropertyValueConverterRegistrar<P> config) {
137+
PropertyValueConverterRegistrar<P> config) {
139138

140139
this.config = config;
141140
this.registration = converter -> config.registerConverter(type, property, converter);
@@ -173,8 +172,8 @@ public static class ReadingConverterRegistrationBuilder<T, S, R, P extends Persi
173172
private final WritingConverterRegistrationBuilder<T, S, P> origin;
174173
private final BiFunction<S, ValueConversionContext<P>, R> writer;
175174

176-
ReadingConverterRegistrationBuilder(@NonNull WritingConverterRegistrationBuilder<T, S, P> origin,
177-
@NonNull BiFunction<S, ValueConversionContext<P>, R> writer) {
175+
ReadingConverterRegistrationBuilder(WritingConverterRegistrationBuilder<T, S, P> origin,
176+
BiFunction<S, ValueConversionContext<P>, R> writer) {
178177

179178
this.origin = origin;
180179
this.writer = writer;

src/main/java/org/springframework/data/convert/SimplePropertyValueConversions.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.springframework.beans.factory.InitializingBean;
2323
import org.springframework.data.convert.PropertyValueConverterFactories.ChainedPropertyValueConverterFactory;
2424
import org.springframework.data.mapping.PersistentProperty;
25-
import org.springframework.lang.NonNull;
2625
import org.springframework.lang.Nullable;
2726
import org.springframework.util.Assert;
2827

@@ -44,8 +43,7 @@
4443
*/
4544
public class SimplePropertyValueConversions implements PropertyValueConversions, InitializingBean {
4645

47-
private static final String NO_CONVERTER_FACTORY_ERROR_MESSAGE =
48-
"PropertyValueConverterFactory is not set; Make sure to either set the converter factory or call afterPropertiesSet() to initialize the object";
46+
private static final String NO_CONVERTER_FACTORY_ERROR_MESSAGE = "PropertyValueConverterFactory is not set; Make sure to either set the converter factory or call afterPropertiesSet() to initialize the object";
4947

5048
private boolean converterCacheEnabled = true;
5149

@@ -57,7 +55,7 @@ public class SimplePropertyValueConversions implements PropertyValueConversions,
5755
* Set the {@link PropertyValueConverterFactory} responsible for creating the actual {@link PropertyValueConverter}.
5856
*
5957
* @param converterFactory {@link PropertyValueConverterFactory} used to create the actual
60-
* {@link PropertyValueConverter}.
58+
* {@link PropertyValueConverter}.
6159
* @see PropertyValueConverterFactory
6260
*/
6361
public void setConverterFactory(@Nullable PropertyValueConverterFactory converterFactory) {
@@ -76,7 +74,7 @@ public PropertyValueConverterFactory getConverterFactory() {
7674
return converterFactory;
7775
}
7876

79-
private @NonNull PropertyValueConverterFactory requireConverterFactory() {
77+
private PropertyValueConverterFactory requireConverterFactory() {
8078

8179
PropertyValueConverterFactory factory = getConverterFactory();
8280

@@ -113,28 +111,27 @@ public ValueConverterRegistry<?> getValueConverterRegistry() {
113111
/**
114112
* Configure whether to use converter the cache. Enabled by default.
115113
*
116-
* @param converterCacheEnabled set to {@literal true} to enable caching of
117-
* {@link PropertyValueConverter converter} instances.
114+
* @param converterCacheEnabled set to {@literal true} to enable caching of {@link PropertyValueConverter converter}
115+
* instances.
118116
*/
119117
public void setConverterCacheEnabled(boolean converterCacheEnabled) {
120118
this.converterCacheEnabled = converterCacheEnabled;
121119
}
122120

123121
/**
124-
* Determines whether a {@link PropertyValueConverter} has been registered for
125-
* the given {@link PersistentProperty property}.
122+
* Determines whether a {@link PropertyValueConverter} has been registered for the given {@link PersistentProperty
123+
* property}.
126124
*
127125
* @param property {@link PersistentProperty} to evaluate.
128-
* @return {@literal true} if a {@link PropertyValueConverter} has been registered for
129-
* the given {@link PersistentProperty property}.
126+
* @return {@literal true} if a {@link PropertyValueConverter} has been registered for the given
127+
* {@link PersistentProperty property}.
130128
* @see PersistentProperty
131129
*/
132130
@Override
133131
public boolean hasValueConverter(PersistentProperty<?> property) {
134132
return requireConverterFactory().getConverter(property) != null;
135133
}
136134

137-
@NonNull
138135
@Override
139136
public <DV, SV, P extends PersistentProperty<P>, D extends ValueConversionContext<P>> PropertyValueConverter<DV, SV, D> getValueConverter(
140137
P property) {
@@ -155,8 +152,7 @@ public void init() {
155152

156153
factoryList.add(resolveConverterFactory());
157154

158-
resolveConverterRegistryAsConverterFactory()
159-
.ifPresent(factoryList::add);
155+
resolveConverterRegistryAsConverterFactory().ifPresent(factoryList::add);
160156

161157
PropertyValueConverterFactory targetFactory = factoryList.size() > 1
162158
? PropertyValueConverterFactory.chained(factoryList)
@@ -166,18 +162,16 @@ public void init() {
166162
: targetFactory;
167163
}
168164

169-
private @NonNull PropertyValueConverterFactory resolveConverterFactory() {
165+
private PropertyValueConverterFactory resolveConverterFactory() {
170166

171167
PropertyValueConverterFactory converterFactory = getConverterFactory();
172168

173-
return converterFactory != null ? converterFactory
174-
: PropertyValueConverterFactory.simple();
169+
return converterFactory != null ? converterFactory : PropertyValueConverterFactory.simple();
175170
}
176171

177172
private Optional<PropertyValueConverterFactory> resolveConverterRegistryAsConverterFactory() {
178173

179-
return Optional.ofNullable(getValueConverterRegistry())
180-
.filter(it -> !it.isEmpty())
174+
return Optional.ofNullable(getValueConverterRegistry()).filter(it -> !it.isEmpty())
181175
.map(PropertyValueConverterFactory::configuredInstance);
182176
}
183177

src/main/java/org/springframework/data/convert/ValueConversionContext.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import org.springframework.data.mapping.PersistentProperty;
1919
import org.springframework.data.util.TypeInformation;
20-
import org.springframework.lang.NonNull;
2120
import org.springframework.lang.Nullable;
2221

2322
/**
@@ -47,7 +46,7 @@ public interface ValueConversionContext<P extends PersistentProperty<P>> {
4746
* @param value {@link Object value} to write; can be {@literal null}.
4847
* @return can be {@literal null}.
4948
* @throws IllegalStateException if value cannot be written as an instance of the
50-
* {@link PersistentProperty#getTypeInformation() property type}.
49+
* {@link PersistentProperty#getTypeInformation() property type}.
5150
* @see PersistentProperty#getTypeInformation()
5251
* @see #write(Object, TypeInformation)
5352
*/
@@ -67,7 +66,7 @@ default Object write(@Nullable Object value) {
6766
* @see TypeInformation
6867
*/
6968
@Nullable
70-
default <T> T write(@Nullable Object value, @NonNull Class<T> target) {
69+
default <T> T write(@Nullable Object value, Class<T> target) {
7170
return write(value, TypeInformation.of(target));
7271
}
7372

@@ -81,7 +80,7 @@ default <T> T write(@Nullable Object value, @NonNull Class<T> target) {
8180
* @see TypeInformation
8281
*/
8382
@Nullable
84-
default <T> T write(@Nullable Object value, @NonNull TypeInformation<T> target) {
83+
default <T> T write(@Nullable Object value, TypeInformation<T> target) {
8584

8685
if (value == null || target.getType().isInstance(value)) {
8786
return target.getType().cast(value);
@@ -97,7 +96,7 @@ default <T> T write(@Nullable Object value, @NonNull TypeInformation<T> target)
9796
* @param value {@link Object value} to be read; can be {@literal null}.
9897
* @return can be {@literal null}.
9998
* @throws IllegalStateException if value cannot be read as an instance of the
100-
* {@link PersistentProperty#getTypeInformation() property type}.
99+
* {@link PersistentProperty#getTypeInformation() property type}.
101100
* @see PersistentProperty#getTypeInformation()
102101
* @see #read(Object, TypeInformation)
103102
*/
@@ -117,7 +116,7 @@ default Object read(@Nullable Object value) {
117116
* @see TypeInformation
118117
*/
119118
@Nullable
120-
default <T> T read(@Nullable Object value, @NonNull Class<T> target) {
119+
default <T> T read(@Nullable Object value, Class<T> target) {
121120
return read(value, TypeInformation.of(target));
122121
}
123122

@@ -131,7 +130,7 @@ default <T> T read(@Nullable Object value, @NonNull Class<T> target) {
131130
* @see TypeInformation
132131
*/
133132
@Nullable
134-
default <T> T read(@Nullable Object value, @NonNull TypeInformation<T> target) {
133+
default <T> T read(@Nullable Object value, TypeInformation<T> target) {
135134

136135
if (value == null || target.getType().isInstance(value)) {
137136
return target.getType().cast(value);

src/main/java/org/springframework/data/repository/util/ClassUtils.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static boolean isGenericRepositoryInterface(@Nullable String interfaceNam
108108
* @deprecated Use {@link #getNumberOfOccurrences(Method, Class)}.
109109
*/
110110
@Deprecated
111-
public static int getNumberOfOccurences(@NonNull Method method, @NonNull Class<?> type) {
111+
public static int getNumberOfOccurences(Method method, Class<?> type) {
112112
return getNumberOfOccurrences(method, type);
113113
}
114114

@@ -124,9 +124,7 @@ public static int getNumberOfOccurences(@NonNull Method method, @NonNull Class<?
124124
*/
125125
public static int getNumberOfOccurrences(@NonNull Method method, @NonNull Class<?> parameterType) {
126126

127-
return (int) Arrays.stream(method.getParameterTypes())
128-
.filter(parameterType::equals)
129-
.count();
127+
return (int) Arrays.stream(method.getParameterTypes()).filter(parameterType::equals).count();
130128
}
131129

132130
/**

0 commit comments

Comments
 (0)