diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java index 4fbfb435875..c4d779e697b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.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. @@ -351,7 +351,9 @@ public class ConstructorArgumentValues { * @return the ValueHolder for the argument, or {@code null} if none set */ @Nullable - public ValueHolder getArgumentValue(int index, @Nullable Class requiredType, @Nullable String requiredName, @Nullable Set usedValueHolders) { + public ValueHolder getArgumentValue(int index, @Nullable Class requiredType, + @Nullable String requiredName, @Nullable Set usedValueHolders) { + Assert.isTrue(index >= 0, "Index must not be negative"); ValueHolder valueHolder = getIndexedArgumentValue(index, requiredType, requiredName); if (valueHolder == null) { diff --git a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperAutoGrowingTests.java b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperAutoGrowingTests.java index 2dddf884e31..78524e632b0 100644 --- a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperAutoGrowingTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperAutoGrowingTests.java @@ -38,7 +38,7 @@ public class BeanWrapperAutoGrowingTests { @BeforeEach - public void setUp() { + public void setup() { wrapper.setAutoGrowNestedPaths(true); } diff --git a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperGenericsTests.java b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperGenericsTests.java index 4412ac8a328..dc44173804f 100644 --- a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperGenericsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperGenericsTests.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. @@ -16,7 +16,6 @@ package org.springframework.beans; -import java.net.MalformedURLException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -86,7 +85,7 @@ public class BeanWrapperGenericsTests { } @Test - public void testGenericList() throws MalformedURLException { + public void testGenericList() throws Exception { GenericBean gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); List input = new ArrayList<>(); @@ -98,7 +97,7 @@ public class BeanWrapperGenericsTests { } @Test - public void testGenericListElement() throws MalformedURLException { + public void testGenericListElement() throws Exception { GenericBean gb = new GenericBean<>(); gb.setResourceList(new ArrayList<>()); BeanWrapper bw = new BeanWrapperImpl(gb); @@ -195,7 +194,7 @@ public class BeanWrapperGenericsTests { } @Test - public void testGenericListOfLists() throws MalformedURLException { + public void testGenericListOfLists() { GenericBean gb = new GenericBean<>(); List> list = new LinkedList<>(); list.add(new LinkedList<>()); @@ -207,7 +206,7 @@ public class BeanWrapperGenericsTests { } @Test - public void testGenericListOfListsWithElementConversion() throws MalformedURLException { + public void testGenericListOfListsWithElementConversion() { GenericBean gb = new GenericBean<>(); List> list = new LinkedList<>(); list.add(new LinkedList<>()); @@ -219,7 +218,7 @@ public class BeanWrapperGenericsTests { } @Test - public void testGenericListOfArrays() throws MalformedURLException { + public void testGenericListOfArrays() { GenericBean gb = new GenericBean<>(); ArrayList list = new ArrayList<>(); list.add(new String[] {"str1", "str2"}); @@ -231,7 +230,7 @@ public class BeanWrapperGenericsTests { } @Test - public void testGenericListOfArraysWithElementConversion() throws MalformedURLException { + public void testGenericListOfArraysWithElementConversion() { GenericBean gb = new GenericBean<>(); ArrayList list = new ArrayList<>(); list.add(new String[] {"str1", "str2"}); @@ -244,7 +243,7 @@ public class BeanWrapperGenericsTests { } @Test - public void testGenericListOfMaps() throws MalformedURLException { + public void testGenericListOfMaps() { GenericBean gb = new GenericBean<>(); List> list = new LinkedList<>(); list.add(new HashMap<>()); @@ -256,7 +255,7 @@ public class BeanWrapperGenericsTests { } @Test - public void testGenericListOfMapsWithElementConversion() throws MalformedURLException { + public void testGenericListOfMapsWithElementConversion() { GenericBean gb = new GenericBean<>(); List> list = new LinkedList<>(); list.add(new HashMap<>()); @@ -268,7 +267,7 @@ public class BeanWrapperGenericsTests { } @Test - public void testGenericMapOfMaps() throws MalformedURLException { + public void testGenericMapOfMaps() { GenericBean gb = new GenericBean<>(); Map> map = new HashMap<>(); map.put("mykey", new HashMap<>()); @@ -280,7 +279,7 @@ public class BeanWrapperGenericsTests { } @Test - public void testGenericMapOfMapsWithElementConversion() throws MalformedURLException { + public void testGenericMapOfMapsWithElementConversion() { GenericBean gb = new GenericBean<>(); Map> map = new HashMap<>(); map.put("mykey", new HashMap<>()); @@ -292,7 +291,7 @@ public class BeanWrapperGenericsTests { } @Test - public void testGenericMapOfLists() throws MalformedURLException { + public void testGenericMapOfLists() { GenericBean gb = new GenericBean<>(); Map> map = new HashMap<>(); map.put(1, new LinkedList<>()); @@ -304,7 +303,7 @@ public class BeanWrapperGenericsTests { } @Test - public void testGenericMapOfListsWithElementConversion() throws MalformedURLException { + public void testGenericMapOfListsWithElementConversion() { GenericBean gb = new GenericBean<>(); Map> map = new HashMap<>(); map.put(1, new LinkedList<>()); @@ -316,7 +315,7 @@ public class BeanWrapperGenericsTests { } @Test - public void testGenericTypeNestingMapOfInteger() throws Exception { + public void testGenericTypeNestingMapOfInteger() { Map map = new HashMap<>(); map.put("testKey", "100"); @@ -330,7 +329,7 @@ public class BeanWrapperGenericsTests { } @Test - public void testGenericTypeNestingMapOfListOfInteger() throws Exception { + public void testGenericTypeNestingMapOfListOfInteger() { Map> map = new HashMap<>(); List list = Arrays.asList(new String[] {"1", "2", "3"}); map.put("testKey", list); @@ -340,13 +339,12 @@ public class BeanWrapperGenericsTests { bw.setPropertyValue("mapOfListOfInteger", map); Object obj = gb.getMapOfListOfInteger().get("testKey").get(0); - boolean condition = obj instanceof Integer; - assertThat(condition).isTrue(); + assertThat(obj instanceof Integer).isTrue(); assertThat(((Integer) obj).intValue()).isEqualTo(1); } @Test - public void testGenericTypeNestingListOfMapOfInteger() throws Exception { + public void testGenericTypeNestingListOfMapOfInteger() { List> list = new LinkedList<>(); Map map = new HashMap<>(); map.put("testKey", "5"); @@ -357,13 +355,12 @@ public class BeanWrapperGenericsTests { bw.setPropertyValue("listOfMapOfInteger", list); Object obj = gb.getListOfMapOfInteger().get(0).get("testKey"); - boolean condition = obj instanceof Integer; - assertThat(condition).isTrue(); + assertThat(obj instanceof Integer).isTrue(); assertThat(((Integer) obj).intValue()).isEqualTo(5); } @Test - public void testGenericTypeNestingMapOfListOfListOfInteger() throws Exception { + public void testGenericTypeNestingMapOfListOfListOfInteger() { Map>> map = new HashMap<>(); List list = Arrays.asList(new String[] {"1", "2", "3"}); map.put("testKey", Collections.singletonList(list)); @@ -373,8 +370,7 @@ public class BeanWrapperGenericsTests { bw.setPropertyValue("mapOfListOfListOfInteger", map); Object obj = gb.getMapOfListOfListOfInteger().get("testKey").get(0).get(0); - boolean condition = obj instanceof Integer; - assertThat(condition).isTrue(); + assertThat(obj instanceof Integer).isTrue(); assertThat(((Integer) obj).intValue()).isEqualTo(1); } @@ -465,7 +461,7 @@ public class BeanWrapperGenericsTests { } @Test - public void testGenericallyTypedIntegerBean() throws Exception { + public void testGenericallyTypedIntegerBean() { GenericIntegerBean gb = new GenericIntegerBean(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("genericProperty", "10"); @@ -476,7 +472,7 @@ public class BeanWrapperGenericsTests { } @Test - public void testGenericallyTypedSetOfIntegerBean() throws Exception { + public void testGenericallyTypedSetOfIntegerBean() { GenericSetOfIntegerBean gb = new GenericSetOfIntegerBean(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("genericProperty", "10"); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java index 5ff2bbd2fcd..40e1d1030e9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.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. @@ -221,7 +221,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic private boolean webApplicationContextInjected = false; /** Flag used to detect whether onRefresh has already been called. */ - private volatile boolean refreshEventReceived = false; + private volatile boolean refreshEventReceived; /** Monitor for synchronized onRefresh execution. */ private final Object onRefreshMonitor = new Object(); @@ -1084,8 +1084,8 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic return; } - String dispatchType = request.getDispatcherType().name(); - boolean initialDispatch = request.getDispatcherType().equals(DispatcherType.REQUEST); + DispatcherType dispatchType = request.getDispatcherType(); + boolean initialDispatch = (dispatchType == DispatcherType.REQUEST); if (failureCause != null) { if (!initialDispatch) { @@ -1109,7 +1109,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic } int status = response.getStatus(); - String headers = ""; // nothing below trace + String headers = ""; // nothing below trace if (logger.isTraceEnabled()) { Collection names = response.getHeaderNames();