From a7b7466274bed2476394cf07d1ecead6a64acde6 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 19 Jul 2023 01:17:25 +0200 Subject: [PATCH] Polishing --- .../aspectj/AspectJExpressionPointcut.java | 10 ++++----- .../aop/framework/CglibAopProxy.java | 7 +++---- .../beans/factory/support/LookupOverride.java | 4 ++-- .../beans/testfixture/beans/TestBean.java | 4 ++-- .../AnnotationConfigApplicationContext.java | 8 +++---- .../AbstractXmlApplicationContext.java | 14 +++++++------ .../mock/env/MockEnvironment.java | 2 +- .../core/env/CommandLinePropertySource.java | 8 +++---- .../util/ConcurrentReferenceHashMap.java | 21 +++++++++---------- .../util/comparator/NullSafeComparator.java | 12 +++++------ .../testfixture/env/MockPropertySource.java | 8 +++---- .../connection/CachingConnectionFactory.java | 4 ++-- .../mock/env/MockEnvironment.java | 11 +++++----- .../mock/env/MockPropertySource.java | 6 ++++-- .../interceptor/RollbackRuleAttribute.java | 4 ++-- .../org/springframework/http/HttpCookie.java | 12 +++++------ .../support/ServletContextResource.java | 2 +- .../web/filter/DelegatingFilterProxy.java | 16 +++++++------- .../web/util/pattern/PathPattern.java | 12 ++++++----- .../client/ExchangeFilterFunctions.java | 4 ++-- .../web/servlet/tags/form/ItemPet.java | 6 ++++-- src/docs/asciidoc/core/core-beans.adoc | 4 ++-- 22 files changed, 93 insertions(+), 86 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java index b2efee6caa..5c79bb5aa7 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -248,8 +248,8 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut /** * If a pointcut expression has been specified in XML, the user cannot - * write {@code and} as "&&" (though && will work). - * We also allow {@code and} between two pointcut sub-expressions. + * write "and" as "&&" (though {@code &&} will work). + *

We also allow "and" between two pointcut sub-expressions. *

This method converts back to {@code &&} for the AspectJ pointcut parser. */ private String replaceBooleanOperators(String pcExpr) { @@ -527,7 +527,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut return false; } AspectJExpressionPointcut otherPc = (AspectJExpressionPointcut) other; - return ObjectUtils.nullSafeEquals(this.getExpression(), otherPc.getExpression()) && + return ObjectUtils.nullSafeEquals(getExpression(), otherPc.getExpression()) && ObjectUtils.nullSafeEquals(this.pointcutDeclarationScope, otherPc.pointcutDeclarationScope) && ObjectUtils.nullSafeEquals(this.pointcutParameterNames, otherPc.pointcutParameterNames) && ObjectUtils.nullSafeEquals(this.pointcutParameterTypes, otherPc.pointcutParameterTypes); @@ -535,7 +535,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut @Override public int hashCode() { - int hashCode = ObjectUtils.nullSafeHashCode(this.getExpression()); + int hashCode = ObjectUtils.nullSafeHashCode(getExpression()); hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.pointcutDeclarationScope); hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.pointcutParameterNames); hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.pointcutParameterTypes); diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java index 1af6ae029a..a172c86c24 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java @@ -424,10 +424,9 @@ class CglibAopProxy implements AopProxy, Serializable { /** - * Method interceptor used for static targets with no advice chain. The call - * is passed directly back to the target. Used when the proxy needs to be - * exposed and it can't be determined that the method won't return - * {@code this}. + * Method interceptor used for static targets with no advice chain. The call is + * passed directly back to the target. Used when the proxy needs to be exposed + * and it can't be determined that the method won't return {@code this}. */ private static class StaticUnadvisedInterceptor implements MethodInterceptor, Serializable { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java index c441bf7e9c..f240013302 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 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. @@ -112,7 +112,7 @@ public class LookupOverride extends MethodOverride { @Override public int hashCode() { - return (29 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.beanName)); + return super.hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.beanName); } @Override diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java index ed54d0d05f..ce870f5784 100644 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java +++ b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2023 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. @@ -477,7 +477,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt @Override public int hashCode() { - return this.age; + return TestBean.class.hashCode(); } @Override diff --git a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.java b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.java index 86ea5feb73..6ca78078cb 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2023 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. @@ -65,7 +65,7 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex * through {@link #register} calls and then manually {@linkplain #refresh refreshed}. */ public AnnotationConfigApplicationContext() { - StartupStep createAnnotatedBeanDefReader = this.getApplicationStartup().start("spring.context.annotated-bean-reader.create"); + StartupStep createAnnotatedBeanDefReader = getApplicationStartup().start("spring.context.annotated-bean-reader.create"); this.reader = new AnnotatedBeanDefinitionReader(this); createAnnotatedBeanDefReader.end(); this.scanner = new ClassPathBeanDefinitionScanner(this); @@ -163,7 +163,7 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex @Override public void register(Class... componentClasses) { Assert.notEmpty(componentClasses, "At least one component class must be specified"); - StartupStep registerComponentClass = this.getApplicationStartup().start("spring.context.component-classes.register") + StartupStep registerComponentClass = getApplicationStartup().start("spring.context.component-classes.register") .tag("classes", () -> Arrays.toString(componentClasses)); this.reader.register(componentClasses); registerComponentClass.end(); @@ -180,7 +180,7 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex @Override public void scan(String... basePackages) { Assert.notEmpty(basePackages, "At least one base package must be specified"); - StartupStep scanPackages = this.getApplicationStartup().start("spring.context.base-packages.scan") + StartupStep scanPackages = getApplicationStartup().start("spring.context.base-packages.scan") .tag("packages", () -> Arrays.toString(basePackages)); this.scanner.scan(basePackages); scanPackages.end(); diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractXmlApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/AbstractXmlApplicationContext.java index 85cb2250b5..c21002abd2 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractXmlApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractXmlApplicationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2023 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. @@ -20,6 +20,7 @@ import java.io.IOException; import org.springframework.beans.BeansException; import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.beans.factory.xml.BeanDefinitionDocumentReader; import org.springframework.beans.factory.xml.ResourceEntityResolver; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.context.ApplicationContext; @@ -84,7 +85,7 @@ public abstract class AbstractXmlApplicationContext extends AbstractRefreshableC // Configure the bean definition reader with this context's // resource loading environment. - beanDefinitionReader.setEnvironment(this.getEnvironment()); + beanDefinitionReader.setEnvironment(getEnvironment()); beanDefinitionReader.setResourceLoader(this); beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this)); @@ -95,12 +96,13 @@ public abstract class AbstractXmlApplicationContext extends AbstractRefreshableC } /** - * Initialize the bean definition reader used for loading the bean - * definitions of this context. Default implementation is empty. + * Initialize the bean definition reader used for loading the bean definitions + * of this context. The default implementation sets the validating flag. *

Can be overridden in subclasses, e.g. for turning off XML validation - * or using a different XmlBeanDefinitionParser implementation. + * or using a different {@link BeanDefinitionDocumentReader} implementation. * @param reader the bean definition reader used by this context - * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader#setDocumentReaderClass + * @see XmlBeanDefinitionReader#setValidating + * @see XmlBeanDefinitionReader#setDocumentReaderClass */ protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) { reader.setValidating(this.validating); diff --git a/spring-context/src/test/java/org/springframework/mock/env/MockEnvironment.java b/spring-context/src/test/java/org/springframework/mock/env/MockEnvironment.java index 6397865a1f..9a533f5635 100644 --- a/spring-context/src/test/java/org/springframework/mock/env/MockEnvironment.java +++ b/spring-context/src/test/java/org/springframework/mock/env/MockEnvironment.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2023 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. diff --git a/spring-core/src/main/java/org/springframework/core/env/CommandLinePropertySource.java b/spring-core/src/main/java/org/springframework/core/env/CommandLinePropertySource.java index 0f80080d1d..c317f5e2dc 100644 --- a/spring-core/src/main/java/org/springframework/core/env/CommandLinePropertySource.java +++ b/spring-core/src/main/java/org/springframework/core/env/CommandLinePropertySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 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. @@ -252,7 +252,7 @@ public abstract class CommandLinePropertySource extends EnumerablePropertySou @Override public final boolean containsProperty(String name) { if (this.nonOptionArgsPropertyName.equals(name)) { - return !this.getNonOptionArgs().isEmpty(); + return !getNonOptionArgs().isEmpty(); } return this.containsOption(name); } @@ -270,7 +270,7 @@ public abstract class CommandLinePropertySource extends EnumerablePropertySou @Nullable public final String getProperty(String name) { if (this.nonOptionArgsPropertyName.equals(name)) { - Collection nonOptionArguments = this.getNonOptionArgs(); + Collection nonOptionArguments = getNonOptionArgs(); if (nonOptionArguments.isEmpty()) { return null; } @@ -278,7 +278,7 @@ public abstract class CommandLinePropertySource extends EnumerablePropertySou return StringUtils.collectionToCommaDelimitedString(nonOptionArguments); } } - Collection optionValues = this.getOptionValues(name); + Collection optionValues = getOptionValues(name); if (optionValues == null) { return null; } 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 3291ca6e07..75507d411d 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-2021 the original author or authors. + * Copyright 2002-2023 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. @@ -752,28 +752,27 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } @Override - public String toString() { - return (this.key + "=" + this.value); - } - - @Override - @SuppressWarnings("rawtypes") - public final boolean equals(@Nullable Object other) { + public boolean equals(@Nullable Object other) { if (this == other) { return true; } - if (!(other instanceof Map.Entry)) { + if (!(other instanceof Map.Entry)) { return false; } - Map.Entry otherEntry = (Map.Entry) other; + Map.Entry otherEntry = (Map.Entry) other; return (ObjectUtils.nullSafeEquals(getKey(), otherEntry.getKey()) && ObjectUtils.nullSafeEquals(getValue(), otherEntry.getValue())); } @Override - public final int hashCode() { + public int hashCode() { return (ObjectUtils.nullSafeHashCode(this.key) ^ ObjectUtils.nullSafeHashCode(this.value)); } + + @Override + public String toString() { + return (this.key + "=" + this.value); + } } diff --git a/spring-core/src/main/java/org/springframework/util/comparator/NullSafeComparator.java b/spring-core/src/main/java/org/springframework/util/comparator/NullSafeComparator.java index 37933af539..6eae4de69b 100644 --- a/spring-core/src/main/java/org/springframework/util/comparator/NullSafeComparator.java +++ b/spring-core/src/main/java/org/springframework/util/comparator/NullSafeComparator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2023 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. @@ -85,7 +85,7 @@ public class NullSafeComparator implements Comparator { * @param nullsLow whether to treat nulls lower or higher than non-null objects */ public NullSafeComparator(Comparator comparator, boolean nullsLow) { - Assert.notNull(comparator, "Non-null Comparator is required"); + Assert.notNull(comparator, "Comparator must not be null"); this.nonNullComparator = comparator; this.nullsLow = nullsLow; } @@ -107,16 +107,16 @@ public class NullSafeComparator implements Comparator { @Override - @SuppressWarnings("unchecked") public boolean equals(@Nullable Object other) { if (this == other) { return true; } - if (!(other instanceof NullSafeComparator)) { + if (!(other instanceof NullSafeComparator)) { return false; } - NullSafeComparator otherComp = (NullSafeComparator) other; - return (this.nonNullComparator.equals(otherComp.nonNullComparator) && this.nullsLow == otherComp.nullsLow); + NullSafeComparator otherComp = (NullSafeComparator) other; + return (this.nonNullComparator.equals(otherComp.nonNullComparator) && + this.nullsLow == otherComp.nullsLow); } @Override diff --git a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/env/MockPropertySource.java b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/env/MockPropertySource.java index ae4944ddcc..a4cbd1f22e 100644 --- a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/env/MockPropertySource.java +++ b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/env/MockPropertySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2023 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,7 +28,7 @@ import org.springframework.core.env.PropertySource; * * The {@link #setProperty} and {@link #withProperty} methods are exposed for * convenience, for example: - *

+ * 
  * {@code
  *   PropertySource source = new MockPropertySource().withProperty("foo", "bar");
  * }
@@ -77,7 +77,7 @@ public class MockPropertySource extends PropertiesPropertySource {
 
 	/**
 	 * Create a new {@code MockPropertySource} with the given name and backed by the given
-	 * {@link Properties} object
+	 * {@link Properties} object.
 	 * @param name the {@linkplain #getName() name} of the property source
 	 * @param properties the properties to use
 	 */
@@ -99,7 +99,7 @@ public class MockPropertySource extends PropertiesPropertySource {
 	 * @return this {@link MockPropertySource} instance
 	 */
 	public MockPropertySource withProperty(String name, Object value) {
-		this.setProperty(name, value);
+		setProperty(name, value);
 		return this;
 	}
 
diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java b/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java
index 3bab8917c7..627ccfa2e3 100644
--- a/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java
+++ b/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2022 the original author or authors.
+ * Copyright 2002-2023 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.
@@ -622,7 +622,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
 
 		@Override
 		public int hashCode() {
-			return (31 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.selector));
+			return super.hashCode() * 31 + ObjectUtils.nullSafeHashCode(this.selector);
 		}
 
 		@Override
diff --git a/spring-test/src/main/java/org/springframework/mock/env/MockEnvironment.java b/spring-test/src/main/java/org/springframework/mock/env/MockEnvironment.java
index 8495e7c37b..88072db943 100644
--- a/spring-test/src/main/java/org/springframework/mock/env/MockEnvironment.java
+++ b/spring-test/src/main/java/org/springframework/mock/env/MockEnvironment.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2018 the original author or authors.
+ * Copyright 2002-2023 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.
@@ -21,8 +21,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
 
 /**
  * Simple {@link ConfigurableEnvironment} implementation exposing
- * {@link #setProperty(String, String)} and {@link #withProperty(String, String)}
- * methods for testing purposes.
+ * {@link #setProperty} and {@link #withProperty} methods for testing purposes.
  *
  * @author Chris Beams
  * @author Sam Brannen
@@ -31,7 +30,8 @@ import org.springframework.core.env.ConfigurableEnvironment;
  */
 public class MockEnvironment extends AbstractEnvironment {
 
-	private MockPropertySource propertySource = new MockPropertySource();
+	private final MockPropertySource propertySource = new MockPropertySource();
+
 
 	/**
 	 * Create a new {@code MockEnvironment} with a single {@link MockPropertySource}.
@@ -40,6 +40,7 @@ public class MockEnvironment extends AbstractEnvironment {
 		getPropertySources().addLast(this.propertySource);
 	}
 
+
 	/**
 	 * Set a property on the underlying {@link MockPropertySource} for this environment.
 	 */
@@ -54,7 +55,7 @@ public class MockEnvironment extends AbstractEnvironment {
 	 * @see MockPropertySource#withProperty
 	 */
 	public MockEnvironment withProperty(String key, String value) {
-		this.setProperty(key, value);
+		setProperty(key, value);
 		return this;
 	}
 
diff --git a/spring-test/src/main/java/org/springframework/mock/env/MockPropertySource.java b/spring-test/src/main/java/org/springframework/mock/env/MockPropertySource.java
index 2f3eb44151..3ef180fcf2 100644
--- a/spring-test/src/main/java/org/springframework/mock/env/MockPropertySource.java
+++ b/spring-test/src/main/java/org/springframework/mock/env/MockPropertySource.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2023 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.
@@ -48,6 +48,7 @@ public class MockPropertySource extends PropertiesPropertySource {
 	 */
 	public static final String MOCK_PROPERTIES_PROPERTY_SOURCE_NAME = "mockProperties";
 
+
 	/**
 	 * Create a new {@code MockPropertySource} named {@value #MOCK_PROPERTIES_PROPERTY_SOURCE_NAME}
 	 * that will maintain its own internal {@link Properties} instance.
@@ -84,6 +85,7 @@ public class MockPropertySource extends PropertiesPropertySource {
 		super(name, properties);
 	}
 
+
 	/**
 	 * Set the given property on the underlying {@link Properties} object.
 	 */
@@ -97,7 +99,7 @@ public class MockPropertySource extends PropertiesPropertySource {
 	 * @return this {@link MockPropertySource} instance
 	 */
 	public MockPropertySource withProperty(String name, Object value) {
-		this.setProperty(name, value);
+		setProperty(name, value);
 		return this;
 	}
 
diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/RollbackRuleAttribute.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/RollbackRuleAttribute.java
index 49327d9345..76754ce77a 100644
--- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/RollbackRuleAttribute.java
+++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/RollbackRuleAttribute.java
@@ -159,8 +159,8 @@ public class RollbackRuleAttribute implements Serializable{
 		if (!(other instanceof RollbackRuleAttribute)) {
 			return false;
 		}
-		RollbackRuleAttribute rhs = (RollbackRuleAttribute) other;
-		return this.exceptionPattern.equals(rhs.exceptionPattern);
+		RollbackRuleAttribute otherAttr = (RollbackRuleAttribute) other;
+		return this.exceptionPattern.equals(otherAttr.exceptionPattern);
 	}
 
 	@Override
diff --git a/spring-web/src/main/java/org/springframework/http/HttpCookie.java b/spring-web/src/main/java/org/springframework/http/HttpCookie.java
index 9ce7fde3a2..279015a91a 100644
--- a/spring-web/src/main/java/org/springframework/http/HttpCookie.java
+++ b/spring-web/src/main/java/org/springframework/http/HttpCookie.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2017 the original author or authors.
+ * Copyright 2002-2023 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.
@@ -56,11 +56,6 @@ public class HttpCookie {
 	}
 
 
-	@Override
-	public int hashCode() {
-		return this.name.hashCode();
-	}
-
 	@Override
 	public boolean equals(@Nullable Object other) {
 		if (this == other) {
@@ -73,6 +68,11 @@ public class HttpCookie {
 		return (this.name.equalsIgnoreCase(otherCookie.getName()));
 	}
 
+	@Override
+	public int hashCode() {
+		return this.name.hashCode();
+	}
+
 	@Override
 	public String toString() {
 		return this.name + '=' + this.value;
diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java
index c8efe40c60..41ba664f10 100644
--- a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java
+++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java
@@ -251,7 +251,7 @@ public class ServletContextResource extends AbstractFileResolvingResource implem
 			return false;
 		}
 		ServletContextResource otherRes = (ServletContextResource) other;
-		return (this.servletContext.equals(otherRes.servletContext) && this.path.equals(otherRes.path));
+		return (this.path.equals(otherRes.path) && this.servletContext.equals(otherRes.servletContext));
 	}
 
 	/**
diff --git a/spring-web/src/main/java/org/springframework/web/filter/DelegatingFilterProxy.java b/spring-web/src/main/java/org/springframework/web/filter/DelegatingFilterProxy.java
index 0dbc224082..dccd60228e 100644
--- a/spring-web/src/main/java/org/springframework/web/filter/DelegatingFilterProxy.java
+++ b/spring-web/src/main/java/org/springframework/web/filter/DelegatingFilterProxy.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2021 the original author or authors.
+ * Copyright 2002-2023 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.
@@ -42,7 +42,7 @@ import org.springframework.web.context.support.WebApplicationContextUtils;
  * be delegated to that bean in the Spring context, which is required to implement
  * the standard Servlet Filter interface.
  *
- * 

This approach is particularly useful for Filter implementation with complex + *

This approach is particularly useful for Filter implementations with complex * setup needs, allowing to apply the full Spring bean definition machinery to * Filter instances. Alternatively, consider standard Filter setup in combination * with looking up service beans from the Spring root application context. @@ -52,11 +52,11 @@ import org.springframework.web.context.support.WebApplicationContextUtils; * Spring application context to manage the lifecycle of that bean. Specifying * the "targetFilterLifecycle" filter init-param as "true" will enforce invocation * of the {@code Filter.init} and {@code Filter.destroy} lifecycle methods - * on the target bean, letting the servlet container manage the filter lifecycle. + * on the target bean, letting the Servlet container manage the filter lifecycle. * - *

As of Spring 3.1, {@code DelegatingFilterProxy} has been updated to optionally - * accept constructor parameters when using a Servlet container's instance-based filter - * registration methods, usually in conjunction with Spring's + *

{@code DelegatingFilterProxy} can optionally accept constructor parameters + * when using a Servlet container's instance-based filter registration methods, + * usually in conjunction with Spring's * {@link org.springframework.web.WebApplicationInitializer} SPI. These constructors allow * for providing the delegate Filter bean directly, or providing the application context * and bean name to fetch, avoiding the need to look up the application context from the @@ -160,10 +160,10 @@ public class DelegatingFilterProxy extends GenericFilterBean { */ public DelegatingFilterProxy(String targetBeanName, @Nullable WebApplicationContext wac) { Assert.hasText(targetBeanName, "Target Filter bean name must not be null or empty"); - this.setTargetBeanName(targetBeanName); + setTargetBeanName(targetBeanName); this.webApplicationContext = wac; if (wac != null) { - this.setEnvironment(wac.getEnvironment()); + setEnvironment(wac.getEnvironment()); } } diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java index f4569d4f26..b3d02b6c26 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java @@ -25,6 +25,7 @@ import java.util.StringJoiner; import org.springframework.http.server.PathContainer; import org.springframework.http.server.PathContainer.Element; +import org.springframework.http.server.PathContainer.PathSegment; import org.springframework.http.server.PathContainer.Separator; import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; @@ -430,6 +431,9 @@ public class PathPattern implements Comparable { @Override public boolean equals(@Nullable Object other) { + if (this == other) { + return true; + } if (!(other instanceof PathPattern)) { return false; } @@ -600,13 +604,11 @@ public class PathPattern implements Comparable { private final PathMatchInfo pathMatchInfo; - PathRemainingMatchInfo(PathContainer pathMatched, PathContainer pathRemaining) { this(pathMatched, pathRemaining, PathMatchInfo.EMPTY); } - PathRemainingMatchInfo(PathContainer pathMatched, PathContainer pathRemaining, - PathMatchInfo pathMatchInfo) { + PathRemainingMatchInfo(PathContainer pathMatched, PathContainer pathRemaining, PathMatchInfo pathMatchInfo) { this.pathRemaining = pathRemaining; this.pathMatched = pathMatched; this.pathMatchInfo = pathMatchInfo; @@ -726,8 +728,8 @@ public class PathPattern implements Comparable { */ String pathElementValue(int pathIndex) { Element element = (pathIndex < this.pathLength) ? this.pathElements.get(pathIndex) : null; - if (element instanceof PathContainer.PathSegment) { - return ((PathContainer.PathSegment)element).valueToMatch(); + if (element instanceof PathSegment) { + return ((PathSegment) element).valueToMatch(); } return ""; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java index 485d5d9e8d..c8be890e40 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2023 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. @@ -183,7 +183,7 @@ public abstract class ExchangeFilterFunctions { @Override public int hashCode() { - return 31 * this.username.hashCode() + this.password.hashCode(); + return this.username.hashCode() * 31 + this.password.hashCode(); } } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/ItemPet.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/ItemPet.java index 18d833cbb4..7d03434599 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/ItemPet.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/ItemPet.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2023 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. @@ -18,6 +18,8 @@ package org.springframework.web.servlet.tags.form; import java.beans.PropertyEditorSupport; +import org.springframework.util.ObjectUtils; + /** * @author Juergen Hoeller */ @@ -50,7 +52,7 @@ public class ItemPet { return false; } ItemPet otherPet = (ItemPet) other; - return (this.name != null && this.name.equals(otherPet.getName())); + return ObjectUtils.nullSafeEquals(this.name, otherPet.getName()); } @Override diff --git a/src/docs/asciidoc/core/core-beans.adoc b/src/docs/asciidoc/core/core-beans.adoc index 5ba8c60b94..e020f6290b 100644 --- a/src/docs/asciidoc/core/core-beans.adoc +++ b/src/docs/asciidoc/core/core-beans.adoc @@ -11061,7 +11061,7 @@ Here is an example of instrumentation in the `AnnotationConfigApplicationContext .Java ---- // create a startup step and start recording - StartupStep scanPackages = this.getApplicationStartup().start("spring.context.base-packages.scan"); + StartupStep scanPackages = getApplicationStartup().start("spring.context.base-packages.scan"); // add tagging information to the current step scanPackages.tag("packages", () -> Arrays.toString(basePackages)); // perform the actual phase we're instrumenting @@ -11073,7 +11073,7 @@ Here is an example of instrumentation in the `AnnotationConfigApplicationContext .Kotlin ---- // create a startup step and start recording - val scanPackages = this.getApplicationStartup().start("spring.context.base-packages.scan") + val scanPackages = getApplicationStartup().start("spring.context.base-packages.scan") // add tagging information to the current step scanPackages.tag("packages", () -> Arrays.toString(basePackages)) // perform the actual phase we're instrumenting