diff --git a/spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java b/spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java index d5c2fa43dd..765a3fb1d6 100644 --- a/spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java +++ b/spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,7 +66,8 @@ public class ConcurrentModel extends ConcurrentHashMap implement @Override - public Object put(String key, Object value) { + @Nullable + public Object put(String key, @Nullable Object value) { if (value != null) { return super.put(key, value); } diff --git a/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java b/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java index 4cec61e31b..f3af11b50a 100644 --- a/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java +++ b/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -299,7 +299,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen @Override @Nullable - public V remove(Object key) { + public V remove(@Nullable Object key) { return doTask(key, new Task(TaskOption.RESTRUCTURE_AFTER, TaskOption.SKIP_IF_EMPTY) { @Override @Nullable @@ -316,7 +316,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } @Override - public boolean remove(Object key, final Object value) { + public boolean remove(@Nullable Object key, final @Nullable Object value) { Boolean result = doTask(key, new Task(TaskOption.RESTRUCTURE_AFTER, TaskOption.SKIP_IF_EMPTY) { @Override protected Boolean execute(@Nullable Reference ref, @Nullable Entry entry) { @@ -333,7 +333,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } @Override - public boolean replace(K key, final V oldValue, final V newValue) { + public boolean replace(@Nullable K key, final @Nullable V oldValue, final @Nullable V newValue) { Boolean result = doTask(key, new Task(TaskOption.RESTRUCTURE_BEFORE, TaskOption.SKIP_IF_EMPTY) { @Override protected Boolean execute(@Nullable Reference ref, @Nullable Entry entry) { @@ -349,7 +349,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen @Override @Nullable - public V replace(K key, final V value) { + public V replace(@Nullable K key, final @Nullable V value) { return doTask(key, new Task(TaskOption.RESTRUCTURE_BEFORE, TaskOption.SKIP_IF_EMPTY) { @Override @Nullable diff --git a/spring-core/src/main/java/org/springframework/util/PropertyPlaceholderHelper.java b/spring-core/src/main/java/org/springframework/util/PropertyPlaceholderHelper.java index b17d6f85fd..c35c048602 100644 --- a/spring-core/src/main/java/org/springframework/util/PropertyPlaceholderHelper.java +++ b/spring-core/src/main/java/org/springframework/util/PropertyPlaceholderHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,9 +28,11 @@ import org.apache.commons.logging.LogFactory; import org.springframework.lang.Nullable; /** - * Utility class for working with Strings that have placeholder values in them. A placeholder takes the form - * {@code ${name}}. Using {@code PropertyPlaceholderHelper} these placeholders can be substituted for - * user-supplied values.

Values for substitution can be supplied using a {@link Properties} instance or + * Utility class for working with Strings that have placeholder values in them. + * A placeholder takes the form {@code ${name}}. Using {@code PropertyPlaceholderHelper} + * these placeholders can be substituted for user-supplied values. + * + *

Values for substitution can be supplied using a {@link Properties} instance or * using a {@link PlaceholderResolver}. * * @author Juergen Hoeller diff --git a/spring-web/src/test/java/org/springframework/http/converter/json/JsonbHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/json/JsonbHttpMessageConverterTests.java index e929dcb67c..7649e8415b 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/json/JsonbHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/json/JsonbHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -72,7 +72,7 @@ public class JsonbHttpMessageConverterTests { public void readTyped() throws IOException { String body = "{\"bytes\":[1,2],\"array\":[\"Foo\",\"Bar\"]," + "\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}"; - MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8")); + MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8)); inputMessage.getHeaders().setContentType(new MediaType("application", "json")); MyBean result = (MyBean) this.converter.read(MyBean.class, inputMessage); @@ -90,7 +90,7 @@ public class JsonbHttpMessageConverterTests { public void readUntyped() throws IOException { String body = "{\"bytes\":[1,2],\"array\":[\"Foo\",\"Bar\"]," + "\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}"; - MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8")); + MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8)); inputMessage.getHeaders().setContentType(new MediaType("application", "json")); HashMap result = (HashMap) this.converter.read(HashMap.class, inputMessage); assertThat(result.get("string")).isEqualTo("Foo"); @@ -167,9 +167,9 @@ public class JsonbHttpMessageConverterTests { } @Test - public void readInvalidJson() throws IOException { + public void readInvalidJson() { String body = "FooBar"; - MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8")); + MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8)); inputMessage.getHeaders().setContentType(new MediaType("application", "json")); assertThatExceptionOfType(HttpMessageNotReadableException.class).isThrownBy(() -> this.converter.read(MyBean.class, inputMessage)); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java index d7363af4ab..81d38fb3b8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java @@ -24,7 +24,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiFunction; import java.util.stream.Collectors; @@ -83,8 +82,7 @@ public class HandlerMappingIntrospector @Nullable private List handlerMappings; - @Nullable - private Map pathPatternHandlerMappings = new ConcurrentHashMap<>(); + private Map pathPatternHandlerMappings = Collections.emptyMap(); /** @@ -106,7 +104,7 @@ public class HandlerMappingIntrospector /** - * Return the configured or detected HandlerMapping's. + * Return the configured or detected {@code HandlerMapping}s. */ public List getHandlerMappings() { return (this.handlerMappings != null ? this.handlerMappings : Collections.emptyList()); @@ -180,7 +178,6 @@ public class HandlerMappingIntrospector BiFunction matchHandler) throws Exception { Assert.notNull(this.handlerMappings, "Handler mappings not initialized"); - Assert.notNull(this.pathPatternHandlerMappings, "Handler mappings with PathPatterns not initialized"); boolean parseRequestPath = !this.pathPatternHandlerMappings.isEmpty(); RequestPath previousPath = null; @@ -247,6 +244,7 @@ public class HandlerMappingIntrospector catch (IOException ex) { throw new IllegalStateException("Could not load '" + path + "': " + ex.getMessage()); } + String value = props.getProperty(HandlerMapping.class.getName()); String[] names = StringUtils.commaDelimitedListToStringArray(value); List result = new ArrayList<>(names.length);