diff --git a/spring-beans/src/main/java/org/springframework/beans/TypeMismatchException.java b/spring-beans/src/main/java/org/springframework/beans/TypeMismatchException.java index 3177c4b20e..4a6f52400e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/TypeMismatchException.java +++ b/spring-beans/src/main/java/org/springframework/beans/TypeMismatchException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 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. @@ -41,10 +41,10 @@ public class TypeMismatchException extends PropertyAccessException { private String propertyName; @Nullable - private transient Object value; + private final transient Object value; @Nullable - private Class requiredType; + private final Class requiredType; /** diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java index 1ee174771c..1acadfe253 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java @@ -294,7 +294,7 @@ public class LocalValidatorFactoryBean extends SpringValidatorAdapter } List mappingStreams = null; if (this.mappingLocations != null) { - mappingStreams = new ArrayList<>(mappingLocations.length); + mappingStreams = new ArrayList<>(this.mappingLocations.length); for (Resource location : this.mappingLocations) { try { InputStream stream = location.getInputStream(); diff --git a/spring-context/src/test/java/org/springframework/context/annotation/EnableLoadTimeWeavingTests.java b/spring-context/src/test/java/org/springframework/context/annotation/EnableLoadTimeWeavingTests.java index 6bc70e12e0..9e253c843b 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/EnableLoadTimeWeavingTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/EnableLoadTimeWeavingTests.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. @@ -40,7 +40,7 @@ public class EnableLoadTimeWeavingTests { @Test public void control() { GenericXmlApplicationContext ctx = - new GenericXmlApplicationContext(getClass(), "EnableLoadTimeWeavingTests-context.xml"); + new GenericXmlApplicationContext(getClass(), "EnableLoadTimeWeavingTests-context.xml"); ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class); } @@ -73,9 +73,11 @@ public class EnableLoadTimeWeavingTests { verify(loadTimeWeaver).addTransformer(isA(ClassFileTransformer.class)); } + @Configuration @EnableLoadTimeWeaving(aspectjWeaving=AspectJWeaving.DISABLED) static class EnableLTWConfig_withAjWeavingDisabled implements LoadTimeWeavingConfigurer { + @Override public LoadTimeWeaver getLoadTimeWeaver() { return mock(LoadTimeWeaver.class); @@ -85,6 +87,7 @@ public class EnableLoadTimeWeavingTests { @Configuration @EnableLoadTimeWeaving(aspectjWeaving=AspectJWeaving.AUTODETECT) static class EnableLTWConfig_withAjWeavingAutodetect implements LoadTimeWeavingConfigurer { + @Override public LoadTimeWeaver getLoadTimeWeaver() { return mock(LoadTimeWeaver.class); @@ -94,9 +97,11 @@ public class EnableLoadTimeWeavingTests { @Configuration @EnableLoadTimeWeaving(aspectjWeaving=AspectJWeaving.ENABLED) static class EnableLTWConfig_withAjWeavingEnabled implements LoadTimeWeavingConfigurer { + @Override public LoadTimeWeaver getLoadTimeWeaver() { return mock(LoadTimeWeaver.class); } } + } diff --git a/spring-test/src/main/java/org/springframework/test/context/event/ApplicationEventsHolder.java b/spring-test/src/main/java/org/springframework/test/context/event/ApplicationEventsHolder.java index aaa8dce302..ad8276acae 100644 --- a/spring-test/src/main/java/org/springframework/test/context/event/ApplicationEventsHolder.java +++ b/spring-test/src/main/java/org/springframework/test/context/event/ApplicationEventsHolder.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. @@ -67,7 +67,6 @@ public abstract class ApplicationEventsHolder { * @throws IllegalStateException if an instance of {@code ApplicationEvents} * has not been registered for the current thread */ - @Nullable public static ApplicationEvents getRequiredApplicationEvents() { ApplicationEvents events = applicationEvents.get(); Assert.state(events != null, "Failed to retrieve ApplicationEvents for the current thread. " + diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpResponse.java index 1382ff2d69..0a7d87281a 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpResponse.java @@ -32,6 +32,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseCookie; import org.springframework.lang.Nullable; +import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -147,10 +148,12 @@ class JettyClientHttpResponse implements ClientHttpResponse { HttpHeaders headers = new HttpHeaders(); Iterable iterator = (Iterable) ReflectionUtils.invokeMethod(getHeadersMethod, response.getResponse()); + Assert.notNull(iterator, "Iterator must not be null"); for (Object field : iterator) { - headers.add( - (String) ReflectionUtils.invokeMethod(getNameMethod, field), - (String) ReflectionUtils.invokeMethod(getValueMethod, field)); + String name = (String) ReflectionUtils.invokeMethod(getNameMethod, field); + Assert.notNull(name, "Header name must not be null"); + String value = (String) ReflectionUtils.invokeMethod(getValueMethod, field); + headers.add(name, value); } return headers; } diff --git a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java index a6a80b3894..bfbc1abe3c 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java @@ -30,6 +30,7 @@ import org.springframework.lang.Nullable; * * @author Arjen Poutsma * @author Juergen Hoeller + * @author Rossen Stoyanchev * @since 3.0 * @param the converted object type */ @@ -67,8 +68,8 @@ public interface HttpMessageConverter { /** * Return the list of media types supported by this converter for the given * class. The list may differ from {@link #getSupportedMediaTypes()} if the - * converter doesn't support given Class or if it support it only for a - * subset of media types. + * converter does not support the given Class or if it supports it only for + * a subset of media types. * @param clazz the type of class to check * @return the list of media types supported for the given class * @since 5.3.4 diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/Jetty10RequestUpgradeStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/Jetty10RequestUpgradeStrategy.java index c757fe259a..cf5ab94581 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/Jetty10RequestUpgradeStrategy.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/Jetty10RequestUpgradeStrategy.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.reactive.socket.server.upgrade; import java.lang.reflect.Method; @@ -35,6 +36,7 @@ import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.http.server.reactive.ServerHttpResponseDecorator; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; +import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; import org.springframework.web.reactive.socket.HandshakeInfo; import org.springframework.web.reactive.socket.WebSocketHandler; @@ -67,7 +69,9 @@ public class Jetty10RequestUpgradeStrategy implements RequestUpgradeStrategy { Class type = loader.loadClass("org.eclipse.jetty.websocket.server.JettyWebSocketServerContainer"); getContainerMethod = type.getMethod("getContainer", ServletContext.class); - upgradeMethod = ReflectionUtils.findMethod(type, "upgrade", (Class[]) null); + Method upgrade = ReflectionUtils.findMethod(type, "upgrade", (Class[]) null); + Assert.state(upgrade != null, "Upgrade method not found"); + upgradeMethod = upgrade; type = loader.loadClass("org.eclipse.jetty.websocket.server.JettyServerUpgradeResponse"); setAcceptedSubProtocol = type.getMethod("setAcceptedSubProtocol", String.class); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java index 2d7c20172a..6e96a08597 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java @@ -203,7 +203,8 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements (noContentType && !message.hasBody())) { return null; } - throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes(targetClass)); + throw new HttpMediaTypeNotSupportedException(contentType, + getSupportedMediaTypes(targetClass != null ? targetClass : Object.class)); } MediaType selectedContentType = contentType; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/jetty/Jetty10RequestUpgradeStrategy.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/jetty/Jetty10RequestUpgradeStrategy.java index 5be9bd925b..6c9dfb0506 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/jetty/Jetty10RequestUpgradeStrategy.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/jetty/Jetty10RequestUpgradeStrategy.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.socket.server.jetty; import java.lang.reflect.Method; @@ -72,7 +73,9 @@ public class Jetty10RequestUpgradeStrategy implements RequestUpgradeStrategy { Class type = loader.loadClass("org.eclipse.jetty.websocket.server.JettyWebSocketServerContainer"); getContainerMethod = type.getMethod("getContainer", ServletContext.class); - upgradeMethod = ReflectionUtils.findMethod(type, "upgrade", (Class[]) null); + Method upgrade = ReflectionUtils.findMethod(type, "upgrade", (Class[]) null); + Assert.state(upgrade != null, "Upgrade method not found"); + upgradeMethod = upgrade; type = loader.loadClass("org.eclipse.jetty.websocket.server.JettyServerUpgradeResponse"); setAcceptedSubProtocol = type.getMethod("setAcceptedSubProtocol", String.class);