Skip to content

Commit 6927e39

Browse files
committed
Merge branch '6.2.x'
2 parents 0202d79 + aa525cc commit 6927e39

File tree

5 files changed

+36
-21
lines changed

5 files changed

+36
-21
lines changed

spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ protected void clearMetadataCache() {
453453
() -> {
454454
CompletableFuture<?> invokeResult = ((CompletableFuture<?>) invokeOperation(invoker));
455455
if (invokeResult == null) {
456-
return null;
456+
throw new IllegalStateException("Returned CompletableFuture must not be null: " + method);
457457
}
458458
return invokeResult.exceptionallyCompose(ex -> {
459459
invokeFailure.set(true);

spring-core/src/main/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrar.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,14 @@ private Entry createEntry(AnnotatedElement element) {
130130

131131
private ReflectiveProcessor instantiateClass(Class<? extends ReflectiveProcessor> type) {
132132
try {
133-
Constructor<? extends ReflectiveProcessor> constructor = type.getDeclaredConstructor();
134-
ReflectionUtils.makeAccessible(constructor);
135-
return constructor.newInstance();
133+
return ReflectionUtils.accessibleConstructor(type).newInstance();
136134
}
137135
catch (Exception ex) {
138136
throw new IllegalStateException("Failed to instantiate " + type, ex);
139137
}
140138
}
141139

140+
142141
private static class DelegatingReflectiveProcessor implements ReflectiveProcessor {
143142

144143
private final Iterable<ReflectiveProcessor> processors;
@@ -151,9 +150,10 @@ private static class DelegatingReflectiveProcessor implements ReflectiveProcesso
151150
public void registerReflectionHints(ReflectionHints hints, AnnotatedElement element) {
152151
this.processors.forEach(processor -> processor.registerReflectionHints(hints, element));
153152
}
154-
155153
}
156154

157-
private record Entry(AnnotatedElement element, ReflectiveProcessor processor) {}
155+
156+
private record Entry(AnnotatedElement element, ReflectiveProcessor processor) {
157+
}
158158

159159
}

spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.io.FileNotFoundException;
2020
import java.io.IOException;
21-
import java.lang.reflect.Constructor;
2221
import java.net.SocketException;
2322
import java.net.UnknownHostException;
2423
import java.util.ArrayList;
@@ -147,9 +146,7 @@ private void addPropertySource(PropertySource<?> propertySource) {
147146

148147
private static PropertySourceFactory instantiateClass(Class<? extends PropertySourceFactory> type) {
149148
try {
150-
Constructor<? extends PropertySourceFactory> constructor = type.getDeclaredConstructor();
151-
ReflectionUtils.makeAccessible(constructor);
152-
return constructor.newInstance();
149+
return ReflectionUtils.accessibleConstructor(type).newInstance();
153150
}
154151
catch (Exception ex) {
155152
throw new IllegalStateException("Failed to instantiate " + type, ex);

spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslator.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public class SQLStateSQLExceptionTranslator extends AbstractFallbackSQLException
7171
"44" // With check violation
7272
);
7373

74+
private static final Set<String> PESSIMISTIC_LOCKING_FAILURE_CODES = Set.of(
75+
"40", // Transaction rollback
76+
"61" // Oracle: deadlock
77+
);
78+
7479
private static final Set<String> DATA_ACCESS_RESOURCE_FAILURE_CODES = Set.of(
7580
"08", // Connection exception
7681
"53", // PostgreSQL: insufficient resources (for example, disk full)
@@ -85,11 +90,6 @@ public class SQLStateSQLExceptionTranslator extends AbstractFallbackSQLException
8590
"S1" // DB2: communication failure
8691
);
8792

88-
private static final Set<String> PESSIMISTIC_LOCKING_FAILURE_CODES = Set.of(
89-
"40", // Transaction rollback
90-
"61" // Oracle: deadlock
91-
);
92-
9393
private static final Set<Integer> DUPLICATE_KEY_ERROR_CODES = Set.of(
9494
1, // Oracle
9595
301, // SAP HANA
@@ -117,18 +117,21 @@ else if (DATA_INTEGRITY_VIOLATION_CODES.contains(classCode)) {
117117
}
118118
return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
119119
}
120-
else if (DATA_ACCESS_RESOURCE_FAILURE_CODES.contains(classCode)) {
121-
return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
122-
}
123-
else if (TRANSIENT_DATA_ACCESS_RESOURCE_CODES.contains(classCode)) {
124-
return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
125-
}
126120
else if (PESSIMISTIC_LOCKING_FAILURE_CODES.contains(classCode)) {
127121
if (indicatesCannotAcquireLock(sqlState)) {
128122
return new CannotAcquireLockException(buildMessage(task, sql, ex), ex);
129123
}
130124
return new PessimisticLockingFailureException(buildMessage(task, sql, ex), ex);
131125
}
126+
else if (DATA_ACCESS_RESOURCE_FAILURE_CODES.contains(classCode)) {
127+
if (indicatesQueryTimeout(sqlState)) {
128+
return new QueryTimeoutException(buildMessage(task, sql, ex), ex);
129+
}
130+
return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
131+
}
132+
else if (TRANSIENT_DATA_ACCESS_RESOURCE_CODES.contains(classCode)) {
133+
return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
134+
}
132135
}
133136

134137
// For MySQL: exception class name indicating a timeout?
@@ -183,4 +186,13 @@ static boolean indicatesCannotAcquireLock(@Nullable String sqlState) {
183186
return "40001".equals(sqlState);
184187
}
185188

189+
/**
190+
* Check whether the given SQL state indicates a {@link QueryTimeoutException},
191+
* with SQL state 57014 as a specific indication.
192+
* @param sqlState the SQL state value
193+
*/
194+
static boolean indicatesQueryTimeout(@Nullable String sqlState) {
195+
return "57014".equals(sqlState);
196+
}
197+
186198
}

spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslatorTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.springframework.dao.DataIntegrityViolationException;
2828
import org.springframework.dao.DuplicateKeyException;
2929
import org.springframework.dao.PessimisticLockingFailureException;
30+
import org.springframework.dao.QueryTimeoutException;
3031
import org.springframework.dao.TransientDataAccessResourceException;
3132
import org.springframework.jdbc.BadSqlGrammarException;
3233

@@ -109,6 +110,11 @@ void translateCannotAcquireLock() {
109110
assertTranslation("40001", CannotAcquireLockException.class);
110111
}
111112

113+
@Test
114+
void translateQueryTimeout() {
115+
assertTranslation("57014", QueryTimeoutException.class);
116+
}
117+
112118
@Test
113119
void translateUncategorized() {
114120
assertTranslation("00000000", null);

0 commit comments

Comments
 (0)