Skip to content

Commit dfae4ee

Browse files
committed
Merge branch '5.3.x'
# Conflicts: # build.gradle # spring-core/src/main/java/org/springframework/cglib/core/ReflectUtils.java # spring-core/src/main/java/org/springframework/core/ResolvableType.java # spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java # spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/R2dbcTransactionManager.java
2 parents 56fc64d + 3c3ae32 commit dfae4ee

File tree

5 files changed

+42
-30
lines changed

5 files changed

+42
-30
lines changed

spring-core/src/main/java/org/springframework/cglib/core/ReflectUtils.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ public static Class defineClass(String className, byte[] b, ClassLoader loader,
437437
return defineClass(className, b, loader, protectionDomain, null);
438438
}
439439

440-
@SuppressWarnings("deprecation")
440+
@SuppressWarnings({"deprecation", "serial"})
441441
public static Class defineClass(String className, byte[] b, ClassLoader loader,
442442
ProtectionDomain protectionDomain, Class<?> contextClass) throws Exception {
443443

@@ -514,6 +514,16 @@ public static Class defineClass(String className, byte[] b, ClassLoader loader,
514514
MethodHandles.Lookup lookup = MethodHandles.privateLookupIn(contextClass, MethodHandles.lookup());
515515
c = lookup.defineClass(b);
516516
}
517+
catch (IllegalAccessException ex) {
518+
throw new CodeGenerationException(ex) {
519+
@Override
520+
public String getMessage() {
521+
return "ClassLoader mismatch for [" + contextClass.getName() +
522+
"]: JVM should be started with --add-opens=java.base/java.lang=ALL-UNNAMED " +
523+
"for ClassLoader.defineClass to be accessible on " + loader.getClass().getName();
524+
}
525+
};
526+
}
517527
catch (Throwable ex) {
518528
throw new CodeGenerationException(ex);
519529
}

spring-core/src/main/java/org/springframework/core/CollectionFactory.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -180,26 +180,25 @@ public static <E> Collection<E> createCollection(Class<?> collectionType, int ca
180180
@SuppressWarnings("unchecked")
181181
public static <E> Collection<E> createCollection(Class<?> collectionType, @Nullable Class<?> elementType, int capacity) {
182182
Assert.notNull(collectionType, "Collection type must not be null");
183-
if (collectionType.isInterface()) {
184-
if (Set.class == collectionType || Collection.class == collectionType) {
185-
return new LinkedHashSet<>(capacity);
186-
}
187-
else if (List.class == collectionType) {
188-
return new ArrayList<>(capacity);
189-
}
190-
else if (SortedSet.class == collectionType || NavigableSet.class == collectionType) {
191-
return new TreeSet<>();
192-
}
193-
else {
194-
throw new IllegalArgumentException("Unsupported Collection interface: " + collectionType.getName());
195-
}
183+
if (LinkedHashSet.class == collectionType || HashSet.class == collectionType ||
184+
Set.class == collectionType || Collection.class == collectionType) {
185+
return new LinkedHashSet<>(capacity);
186+
}
187+
else if (ArrayList.class == collectionType || List.class == collectionType) {
188+
return new ArrayList<>(capacity);
189+
}
190+
else if (LinkedList.class == collectionType) {
191+
return new LinkedList<>();
192+
}
193+
else if (SortedSet.class == collectionType || NavigableSet.class == collectionType) {
194+
return new TreeSet<>();
196195
}
197196
else if (EnumSet.class.isAssignableFrom(collectionType)) {
198197
Assert.notNull(elementType, "Cannot create EnumSet for unknown element type");
199198
return EnumSet.noneOf(asEnumType(elementType));
200199
}
201200
else {
202-
if (!Collection.class.isAssignableFrom(collectionType)) {
201+
if (collectionType.isInterface() || !Collection.class.isAssignableFrom(collectionType)) {
203202
throw new IllegalArgumentException("Unsupported Collection type: " + collectionType.getName());
204203
}
205204
try {

spring-core/src/main/java/org/springframework/core/ResolvableType.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,8 @@ public Class<?> getRawClass() {
221221
/**
222222
* Return the underlying source of the resolvable type. Will return a {@link Field},
223223
* {@link MethodParameter} or {@link Type} depending on how the {@link ResolvableType}
224-
* was constructed. With the exception of the {@link #NONE} constant, this method will
225-
* never return {@code null}. This method is primarily to provide access to additional
226-
* type information or meta-data that alternative JVM languages may provide.
224+
* was constructed. This method is primarily to provide access to additional type
225+
* information or meta-data that alternative JVM languages may provide.
227226
*/
228227
public Object getSource() {
229228
Object source = (this.typeProvider != null ? this.typeProvider.getSource() : null);
@@ -1096,20 +1095,20 @@ public static ResolvableType forClassWithGenerics(Class<?> clazz, ResolvableType
10961095
* convey generic information but if it implements {@link ResolvableTypeProvider} a
10971096
* more precise {@link ResolvableType} can be used than the simple one based on
10981097
* the {@link #forClass(Class) Class instance}.
1099-
* @param instance the instance
1100-
* @return a {@link ResolvableType} for the specified instance
1098+
* @param instance the instance (possibly {@code null})
1099+
* @return a {@link ResolvableType} for the specified instance,
1100+
* or {@code NONE} for {@code null}
11011101
* @since 4.2
11021102
* @see ResolvableTypeProvider
11031103
*/
1104-
public static ResolvableType forInstance(Object instance) {
1105-
Assert.notNull(instance, "Instance must not be null");
1104+
public static ResolvableType forInstance(@Nullable Object instance) {
11061105
if (instance instanceof ResolvableTypeProvider resolvableTypeProvider) {
11071106
ResolvableType type = resolvableTypeProvider.getResolvableType();
11081107
if (type != null) {
11091108
return type;
11101109
}
11111110
}
1112-
return ResolvableType.forClass(instance.getClass());
1111+
return (instance != null ? forClass(instance.getClass()) : NONE);
11131112
}
11141113

11151114
/**

spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,9 @@ void forRawClassAssignableFromTypeVariable() throws Exception {
146146
assertThat(typeVariable.isAssignableFrom(raw)).isTrue();
147147
}
148148

149-
@Test
150-
void forInstanceMustNotBeNull() throws Exception {
151-
assertThatIllegalArgumentException()
152-
.isThrownBy(() -> ResolvableType.forInstance(null))
153-
.withMessage("Instance must not be null");
149+
@Test // gh-28776
150+
void forInstanceNull() throws Exception {
151+
assertThat(ResolvableType.forInstance(null)).isEqualTo(ResolvableType.NONE);
154152
}
155153

156154
@Test

spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,6 +26,9 @@
2626
import java.sql.PreparedStatement;
2727
import java.sql.SQLException;
2828
import java.sql.Types;
29+
import java.time.LocalDate;
30+
import java.time.LocalDateTime;
31+
import java.time.LocalTime;
2932
import java.util.Arrays;
3033
import java.util.Calendar;
3134
import java.util.Collection;
@@ -98,6 +101,9 @@ public abstract class StatementCreatorUtils {
98101
javaTypeToSqlTypeMap.put(double.class, Types.DOUBLE);
99102
javaTypeToSqlTypeMap.put(Double.class, Types.DOUBLE);
100103
javaTypeToSqlTypeMap.put(BigDecimal.class, Types.DECIMAL);
104+
javaTypeToSqlTypeMap.put(LocalDate.class, Types.DATE);
105+
javaTypeToSqlTypeMap.put(LocalTime.class, Types.TIME);
106+
javaTypeToSqlTypeMap.put(LocalDateTime.class, Types.TIMESTAMP);
101107
javaTypeToSqlTypeMap.put(java.sql.Date.class, Types.DATE);
102108
javaTypeToSqlTypeMap.put(java.sql.Time.class, Types.TIME);
103109
javaTypeToSqlTypeMap.put(java.sql.Timestamp.class, Types.TIMESTAMP);

0 commit comments

Comments
 (0)