diff --git a/spring-beans/src/jmh/java/org/springframework/beans/factory/DefaultListableBeanFactoryBenchmark.java b/spring-beans/src/jmh/java/org/springframework/beans/factory/DefaultListableBeanFactoryBenchmark.java index 4679dd17de3..58e6b215bba 100644 --- a/spring-beans/src/jmh/java/org/springframework/beans/factory/DefaultListableBeanFactoryBenchmark.java +++ b/spring-beans/src/jmh/java/org/springframework/beans/factory/DefaultListableBeanFactoryBenchmark.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. diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessorUtils.java b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessorUtils.java index c3583927f5d..465b3ff8b1d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessorUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessorUtils.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-context/src/main/java/org/springframework/context/annotation/LoadTimeWeavingConfiguration.java b/spring-context/src/main/java/org/springframework/context/annotation/LoadTimeWeavingConfiguration.java index c08dd42b244..86b1ede8f70 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/LoadTimeWeavingConfiguration.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/LoadTimeWeavingConfiguration.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. diff --git a/spring-context/src/main/java/org/springframework/format/datetime/DateFormatter.java b/spring-context/src/main/java/org/springframework/format/datetime/DateFormatter.java index 4b909a33247..c3f8811a914 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/DateFormatter.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/DateFormatter.java @@ -269,7 +269,7 @@ public class DateFormatter implements Formatter { if (timeStyle != -1) { return DateFormat.getTimeInstance(timeStyle, locale); } - throw new IllegalStateException("Unsupported style pattern '" + this.stylePattern + "'"); + throw unsupportedStylePatternException(); } return DateFormat.getDateInstance(this.style, locale); @@ -284,10 +284,14 @@ public class DateFormatter implements Formatter { case 'L' -> DateFormat.LONG; case 'F' -> DateFormat.FULL; case '-' -> -1; - default -> throw new IllegalStateException("Unsupported style pattern '" + this.stylePattern + "'"); + default -> throw unsupportedStylePatternException(); }; } - throw new IllegalStateException("Unsupported style pattern '" + this.stylePattern + "'"); + throw unsupportedStylePatternException(); + } + + private IllegalStateException unsupportedStylePatternException() { + return new IllegalStateException("Unsupported style pattern '" + this.stylePattern + "'"); } } diff --git a/spring-core/src/main/java/org/springframework/util/xml/ListBasedXMLEventReader.java b/spring-core/src/main/java/org/springframework/util/xml/ListBasedXMLEventReader.java index abb303a2361..488b70b47d9 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/ListBasedXMLEventReader.java +++ b/spring-core/src/main/java/org/springframework/util/xml/ListBasedXMLEventReader.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. diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java index c6979a21c81..9e68004e6b6 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java @@ -1656,20 +1656,20 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { // Invocation on ConnectionProxy interface coming in... return switch (method.getName()) { + // Only consider equal when proxies are identical. case "equals" -> (proxy == args[0]); - // Only consider equal when proxies are identical. + // Use hashCode of PersistenceManager proxy. case "hashCode" -> System.identityHashCode(proxy); - // Use hashCode of PersistenceManager proxy. + // Handle close method: suppress, not valid. case "close" -> null; - // Handle close method: suppress, not valid. case "isClosed" -> false; + // Handle getTargetConnection method: return underlying Connection. case "getTargetConnection" -> this.target; - // Handle getTargetConnection method: return underlying Connection. case "unwrap" -> (((Class) args[0]).isInstance(proxy) ? proxy : this.target.unwrap((Class) args[0])); case "isWrapperFor" -> (((Class) args[0]).isInstance(proxy) || this.target.isWrapperFor((Class) args[0])); default -> { - // Invoke method on target Connection. try { + // Invoke method on target Connection. Object retVal = method.invoke(this.target, args); // If return value is a JDBC Statement, apply statement settings diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java index 59074efea62..c978e37aa04 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java @@ -350,20 +350,20 @@ public class SingleConnectionDataSource extends DriverManagerDataSource // Invocation on ConnectionProxy interface coming in... return switch (method.getName()) { + // Only consider equal when proxies are identical. case "equals" -> (proxy == args[0]); - // Only consider equal when proxies are identical. + // Use hashCode of Connection proxy. case "hashCode" -> System.identityHashCode(proxy); - // Use hashCode of Connection proxy. + // Handle close method: don't pass the call on. case "close" -> null; - // Handle close method: don't pass the call on. case "isClosed" -> this.target.isClosed(); + // Handle getTargetConnection method: return underlying Connection. case "getTargetConnection" -> this.target; - // Handle getTargetConnection method: return underlying Connection. case "unwrap" -> (((Class) args[0]).isInstance(proxy) ? proxy : this.target.unwrap((Class) args[0])); case "isWrapperFor" -> (((Class) args[0]).isInstance(proxy) || this.target.isWrapperFor((Class) args[0])); default -> { - // Invoke method on target Connection. try { + // Invoke method on target Connection. yield method.invoke(this.target, args); } catch (InvocationTargetException ex) { diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java b/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java index 763fba93ece..5f5850dc199 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java @@ -625,7 +625,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti else { throw new jakarta.jms.IllegalStateException( "setClientID call not supported on proxy for shared Connection. " + - "Set the 'clientId' property on the SingleConnectionFactory instead."); + "Set the 'clientId' property on the SingleConnectionFactory instead."); } } case "setExceptionListener" -> { @@ -647,9 +647,9 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti else { throw new jakarta.jms.IllegalStateException( "setExceptionListener call not supported on proxy for shared Connection. " + - "Set the 'exceptionListener' property on the SingleConnectionFactory instead. " + - "Alternatively, activate SingleConnectionFactory's 'reconnectOnException' feature, " + - "which will allow for registering further ExceptionListeners to the recovery chain."); + "Set the 'exceptionListener' property on the SingleConnectionFactory instead. " + + "Alternatively, activate SingleConnectionFactory's 'reconnectOnException' feature, " + + "which will allow for registering further ExceptionListeners to the recovery chain."); } } } diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java b/spring-jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java index 389026e2511..ad903157548 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java @@ -332,21 +332,21 @@ public class TransactionAwareConnectionFactoryProxy // Invocation on SessionProxy interface coming in... return switch (method.getName()) { + // Only consider equal when proxies are identical. case "equals" -> (proxy == args[0]); - // Only consider equal when proxies are identical. + // Use hashCode of Connection proxy. case "hashCode" -> System.identityHashCode(proxy); - // Use hashCode of Connection proxy. case "commit" -> throw new TransactionInProgressException("Commit call not allowed within a managed transaction"); case "rollback" -> throw new TransactionInProgressException("Rollback call not allowed within a managed transaction"); + // Handle close method: not to be closed within a transaction. case "close" -> null; - // Handle close method: not to be closed within a transaction. + // Handle getTargetSession method: return underlying Session. case "getTargetSession" -> this.target; - // Handle getTargetSession method: return underlying Session. default -> { - // Invoke method on target Session. try { + // Invoke method on target Session. yield method.invoke(this.target, args); } catch (InvocationTargetException ex) { diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTemplate.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTemplate.java index d5870122f22..74d662f3dc5 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTemplate.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTemplate.java @@ -1151,15 +1151,15 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean // Invocation on Session interface coming in... return switch (method.getName()) { + // Only consider equal when proxies are identical. case "equals" -> (proxy == args[0]); - // Only consider equal when proxies are identical. + // Use hashCode of Session proxy. case "hashCode" -> System.identityHashCode(proxy); - // Use hashCode of Session proxy. + // Handle close method: suppress, not valid. case "close" -> null; - // Handle close method: suppress, not valid. default -> { - // Invoke method on target Session. try { + // Invoke method on target Session. Object retVal = method.invoke(this.target, args); // If return value is a Query or Criteria, apply transaction timeout. diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java index a931561dbf1..6ab0a086025 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java @@ -413,17 +413,17 @@ public class LocalSessionFactoryBuilder extends Configuration { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { return switch (method.getName()) { + // Only consider equal when proxies are identical. case "equals" -> (proxy == args[0]); - // Only consider equal when proxies are identical. + // Use hashCode of EntityManagerFactory proxy. case "hashCode" -> System.identityHashCode(proxy); - // Use hashCode of EntityManagerFactory proxy. case "getProperties" -> getProperties(); + // Call coming in through InfrastructureProxy interface... case "getWrappedObject" -> getSessionFactory(); - // Call coming in through InfrastructureProxy interface... default -> { - // Regular delegation to the target SessionFactory, - // enforcing its full initialization... try { + // Regular delegation to the target SessionFactory, + // enforcing its full initialization... yield method.invoke(getSessionFactory(), args); } catch (InvocationTargetException ex) { diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java index 1fcd9a58985..60cf247d091 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.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. diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java b/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java index 36428552302..6acec2dfa54 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.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. diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java b/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java index 7c7c0827101..e5991b3913b 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java @@ -264,7 +264,7 @@ public abstract class SharedEntityManagerCreator { case "getTransaction" -> { throw new IllegalStateException( "Not allowed to create transaction on shared EntityManager - " + - "use Spring transactions or EJB CMT instead"); + "use Spring transactions or EJB CMT instead"); } } diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.java index dfa27270a23..24854d6da14 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.java @@ -252,16 +252,16 @@ public class SingleConnectionFactory extends DelegatingConnectionFactory @Nullable public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { return switch (method.getName()) { + // Only consider equal when proxies are identical. case "equals" -> proxy == args[0]; - // Only consider equal when proxies are identical. + // Use hashCode of PersistenceManager proxy. case "hashCode" -> System.identityHashCode(proxy); - // Use hashCode of PersistenceManager proxy. case "unwrap" -> this.target; + // Handle close method: suppress, not valid. case "close" -> Mono.empty(); - // Handle close method: suppress, not valid. default -> { - // Invoke method on target Connection. try { + // Invoke method on target Connection. yield method.invoke(this.target, args); } catch (InvocationTargetException ex) { diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxy.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxy.java index a480ff17408..c9d47089e87 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxy.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxy.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. @@ -145,17 +145,17 @@ public class TransactionAwareConnectionFactoryProxy extends DelegatingConnection return switch (method.getName()) { case "unwrap" -> this.connection; + // Handle close method: only close if not within a transaction. case "close" -> ConnectionFactoryUtils.doReleaseConnection(this.connection, this.targetConnectionFactory) .doOnSubscribe(n -> this.closed = true); - // Handle close method: only close if not within a transaction. case "isClosed" -> this.closed; default -> { if (this.closed) { throw new IllegalStateException("Connection handle already closed"); } - // Invoke method on target Connection. try { + // Invoke method on target Connection. yield method.invoke(this.connection, args); } catch (InvocationTargetException ex) { @@ -167,7 +167,7 @@ public class TransactionAwareConnectionFactoryProxy extends DelegatingConnection private String proxyToString(@Nullable Object proxy) { // Allow for differentiating between the proxy and the raw Connection. - return "Transaction-aware proxy for target Connection [" + this.connection.toString() + "]"; + return "Transaction-aware proxy for target Connection [" + this.connection + "]"; } } diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java index ff1c91ce4a6..e043240cd92 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java @@ -520,16 +520,16 @@ final class DefaultDatabaseClient implements DatabaseClient { @Nullable public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { return switch (method.getName()) { + // Only consider equal when proxies are identical. case "equals" -> proxy == args[0]; - // Only consider equal when proxies are identical. + // Use hashCode of PersistenceManager proxy. case "hashCode" -> System.identityHashCode(proxy); - // Use hashCode of PersistenceManager proxy. case "unwrap" -> this.target; + // Handle close method: suppress, not valid. case "close" -> Mono.error(new UnsupportedOperationException("Close is not supported!")); - // Handle close method: suppress, not valid. default -> { - // Invoke method on target Connection. try { + // Invoke method on target Connection. yield method.invoke(this.target, args); } catch (InvocationTargetException ex) { diff --git a/spring-tx/src/main/java/org/springframework/transaction/jta/JtaAfterCompletionSynchronization.java b/spring-tx/src/main/java/org/springframework/transaction/jta/JtaAfterCompletionSynchronization.java index b037e12ee20..fede45badef 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/jta/JtaAfterCompletionSynchronization.java +++ b/spring-tx/src/main/java/org/springframework/transaction/jta/JtaAfterCompletionSynchronization.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.