Skip to content

Commit

Permalink
Nullability refinements and related polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed May 11, 2021
1 parent be52ec8 commit 1469bdb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -66,7 +66,8 @@ public ConcurrentModel(Object attributeValue) {


@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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -299,7 +299,7 @@ protected V execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> entry,

@Override
@Nullable
public V remove(Object key) {
public V remove(@Nullable Object key) {
return doTask(key, new Task<V>(TaskOption.RESTRUCTURE_AFTER, TaskOption.SKIP_IF_EMPTY) {
@Override
@Nullable
Expand All @@ -316,7 +316,7 @@ protected V execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> entry)
}

@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<Boolean>(TaskOption.RESTRUCTURE_AFTER, TaskOption.SKIP_IF_EMPTY) {
@Override
protected Boolean execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> entry) {
Expand All @@ -333,7 +333,7 @@ protected Boolean execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> e
}

@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<Boolean>(TaskOption.RESTRUCTURE_BEFORE, TaskOption.SKIP_IF_EMPTY) {
@Override
protected Boolean execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> entry) {
Expand All @@ -349,7 +349,7 @@ protected Boolean execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> e

@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<V>(TaskOption.RESTRUCTURE_BEFORE, TaskOption.SKIP_IF_EMPTY) {
@Override
@Nullable
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -28,9 +28,11 @@
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. <p> 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.
*
* <p>Values for substitution can be supplied using a {@link Properties} instance or
* using a {@link PlaceholderResolver}.
*
* @author Juergen Hoeller
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -72,7 +72,7 @@ public void canReadAndWriteMicroformats() {
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);

Expand All @@ -90,7 +90,7 @@ public void readTyped() throws IOException {
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<String, Object> result = (HashMap<String, Object>) this.converter.read(HashMap.class, inputMessage);
assertThat(result.get("string")).isEqualTo("Foo");
Expand Down Expand Up @@ -167,9 +167,9 @@ public void writeUTF16() throws IOException {
}

@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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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;

Expand Down Expand Up @@ -83,8 +82,7 @@ public class HandlerMappingIntrospector
@Nullable
private List<HandlerMapping> handlerMappings;

@Nullable
private Map<HandlerMapping, PathPatternMatchableHandlerMapping> pathPatternHandlerMappings = new ConcurrentHashMap<>();
private Map<HandlerMapping, PathPatternMatchableHandlerMapping> pathPatternHandlerMappings = Collections.emptyMap();


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


/**
* Return the configured or detected HandlerMapping's.
* Return the configured or detected {@code HandlerMapping}s.
*/
public List<HandlerMapping> getHandlerMappings() {
return (this.handlerMappings != null ? this.handlerMappings : Collections.emptyList());
Expand Down Expand Up @@ -180,7 +178,6 @@ private <T> T doWithMatchingMapping(
BiFunction<HandlerMapping, HandlerExecutionChain, T> 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;
Expand Down Expand Up @@ -247,6 +244,7 @@ private static List<HandlerMapping> initFallback(ApplicationContext applicationC
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<HandlerMapping> result = new ArrayList<>(names.length);
Expand Down

0 comments on commit 1469bdb

Please sign in to comment.