Skip to content

Commit 1469bdb

Browse files
committed
Nullability refinements and related polishing
1 parent be52ec8 commit 1469bdb

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -66,7 +66,8 @@ public ConcurrentModel(Object attributeValue) {
6666

6767

6868
@Override
69-
public Object put(String key, Object value) {
69+
@Nullable
70+
public Object put(String key, @Nullable Object value) {
7071
if (value != null) {
7172
return super.put(key, value);
7273
}

spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -299,7 +299,7 @@ protected V execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> entry,
299299

300300
@Override
301301
@Nullable
302-
public V remove(Object key) {
302+
public V remove(@Nullable Object key) {
303303
return doTask(key, new Task<V>(TaskOption.RESTRUCTURE_AFTER, TaskOption.SKIP_IF_EMPTY) {
304304
@Override
305305
@Nullable
@@ -316,7 +316,7 @@ protected V execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> entry)
316316
}
317317

318318
@Override
319-
public boolean remove(Object key, final Object value) {
319+
public boolean remove(@Nullable Object key, final @Nullable Object value) {
320320
Boolean result = doTask(key, new Task<Boolean>(TaskOption.RESTRUCTURE_AFTER, TaskOption.SKIP_IF_EMPTY) {
321321
@Override
322322
protected Boolean execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> entry) {
@@ -333,7 +333,7 @@ protected Boolean execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> e
333333
}
334334

335335
@Override
336-
public boolean replace(K key, final V oldValue, final V newValue) {
336+
public boolean replace(@Nullable K key, final @Nullable V oldValue, final @Nullable V newValue) {
337337
Boolean result = doTask(key, new Task<Boolean>(TaskOption.RESTRUCTURE_BEFORE, TaskOption.SKIP_IF_EMPTY) {
338338
@Override
339339
protected Boolean execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> entry) {
@@ -349,7 +349,7 @@ protected Boolean execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> e
349349

350350
@Override
351351
@Nullable
352-
public V replace(K key, final V value) {
352+
public V replace(@Nullable K key, final @Nullable V value) {
353353
return doTask(key, new Task<V>(TaskOption.RESTRUCTURE_BEFORE, TaskOption.SKIP_IF_EMPTY) {
354354
@Override
355355
@Nullable

spring-core/src/main/java/org/springframework/util/PropertyPlaceholderHelper.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -28,9 +28,11 @@
2828
import org.springframework.lang.Nullable;
2929

3030
/**
31-
* Utility class for working with Strings that have placeholder values in them. A placeholder takes the form
32-
* {@code ${name}}. Using {@code PropertyPlaceholderHelper} these placeholders can be substituted for
33-
* user-supplied values. <p> Values for substitution can be supplied using a {@link Properties} instance or
31+
* Utility class for working with Strings that have placeholder values in them.
32+
* A placeholder takes the form {@code ${name}}. Using {@code PropertyPlaceholderHelper}
33+
* these placeholders can be substituted for user-supplied values.
34+
*
35+
* <p>Values for substitution can be supplied using a {@link Properties} instance or
3436
* using a {@link PlaceholderResolver}.
3537
*
3638
* @author Juergen Hoeller

spring-web/src/test/java/org/springframework/http/converter/json/JsonbHttpMessageConverterTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -72,7 +72,7 @@ public void canReadAndWriteMicroformats() {
7272
public void readTyped() throws IOException {
7373
String body = "{\"bytes\":[1,2],\"array\":[\"Foo\",\"Bar\"]," +
7474
"\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}";
75-
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
75+
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8));
7676
inputMessage.getHeaders().setContentType(new MediaType("application", "json"));
7777
MyBean result = (MyBean) this.converter.read(MyBean.class, inputMessage);
7878

@@ -90,7 +90,7 @@ public void readTyped() throws IOException {
9090
public void readUntyped() throws IOException {
9191
String body = "{\"bytes\":[1,2],\"array\":[\"Foo\",\"Bar\"]," +
9292
"\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}";
93-
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
93+
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8));
9494
inputMessage.getHeaders().setContentType(new MediaType("application", "json"));
9595
HashMap<String, Object> result = (HashMap<String, Object>) this.converter.read(HashMap.class, inputMessage);
9696
assertThat(result.get("string")).isEqualTo("Foo");
@@ -167,9 +167,9 @@ public void writeUTF16() throws IOException {
167167
}
168168

169169
@Test
170-
public void readInvalidJson() throws IOException {
170+
public void readInvalidJson() {
171171
String body = "FooBar";
172-
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
172+
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8));
173173
inputMessage.getHeaders().setContentType(new MediaType("application", "json"));
174174
assertThatExceptionOfType(HttpMessageNotReadableException.class).isThrownBy(() ->
175175
this.converter.read(MyBean.class, inputMessage));

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.List;
2525
import java.util.Map;
2626
import java.util.Properties;
27-
import java.util.concurrent.ConcurrentHashMap;
2827
import java.util.function.BiFunction;
2928
import java.util.stream.Collectors;
3029

@@ -83,8 +82,7 @@ public class HandlerMappingIntrospector
8382
@Nullable
8483
private List<HandlerMapping> handlerMappings;
8584

86-
@Nullable
87-
private Map<HandlerMapping, PathPatternMatchableHandlerMapping> pathPatternHandlerMappings = new ConcurrentHashMap<>();
85+
private Map<HandlerMapping, PathPatternMatchableHandlerMapping> pathPatternHandlerMappings = Collections.emptyMap();
8886

8987

9088
/**
@@ -106,7 +104,7 @@ public HandlerMappingIntrospector(ApplicationContext context) {
106104

107105

108106
/**
109-
* Return the configured or detected HandlerMapping's.
107+
* Return the configured or detected {@code HandlerMapping}s.
110108
*/
111109
public List<HandlerMapping> getHandlerMappings() {
112110
return (this.handlerMappings != null ? this.handlerMappings : Collections.emptyList());
@@ -180,7 +178,6 @@ private <T> T doWithMatchingMapping(
180178
BiFunction<HandlerMapping, HandlerExecutionChain, T> matchHandler) throws Exception {
181179

182180
Assert.notNull(this.handlerMappings, "Handler mappings not initialized");
183-
Assert.notNull(this.pathPatternHandlerMappings, "Handler mappings with PathPatterns not initialized");
184181

185182
boolean parseRequestPath = !this.pathPatternHandlerMappings.isEmpty();
186183
RequestPath previousPath = null;
@@ -247,6 +244,7 @@ private static List<HandlerMapping> initFallback(ApplicationContext applicationC
247244
catch (IOException ex) {
248245
throw new IllegalStateException("Could not load '" + path + "': " + ex.getMessage());
249246
}
247+
250248
String value = props.getProperty(HandlerMapping.class.getName());
251249
String[] names = StringUtils.commaDelimitedListToStringArray(value);
252250
List<HandlerMapping> result = new ArrayList<>(names.length);

0 commit comments

Comments
 (0)