Skip to content

Commit 5b44449

Browse files
committed
Reduce amount of empty Class[] produced at bootstrap time
1 parent c8c1e61 commit 5b44449

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

spring-core/src/main/java/org/springframework/util/ClassUtils.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
*/
5757
public abstract class ClassUtils {
5858

59+
public static final Class<?>[] EMPTY_CLASS_ARRAY = {};
60+
5961
/** Suffix for array class names: {@code "[]"}. */
6062
public static final String ARRAY_SUFFIX = "[]";
6163

@@ -682,7 +684,7 @@ public static String classNamesToString(@Nullable Collection<Class<?>> classes)
682684
* @see StringUtils#toStringArray
683685
*/
684686
public static Class<?>[] toClassArray(Collection<Class<?>> collection) {
685-
return collection.toArray(new Class<?>[0]);
687+
return collection.isEmpty() ? EMPTY_CLASS_ARRAY : collection.toArray(EMPTY_CLASS_ARRAY);
686688
}
687689

688690
/**
@@ -1068,6 +1070,17 @@ public static boolean hasConstructor(Class<?> clazz, Class<?>... paramTypes) {
10681070
return (getConstructorIfAvailable(clazz, paramTypes) != null);
10691071
}
10701072

1073+
/**
1074+
* Determine whether the given class has a public no-args constructor.
1075+
* <p>Essentially translates {@code NoSuchMethodException} to "false".
1076+
* @param clazz the clazz to analyze
1077+
* @return whether the class has public no-args constructor
1078+
* @see Class#getMethod
1079+
*/
1080+
public static boolean hasConstructor(Class<?> clazz) {
1081+
return hasConstructor(clazz, EMPTY_CLASS_ARRAY);
1082+
}
1083+
10711084
/**
10721085
* Determine whether the given class has a public constructor with the given signature,
10731086
* and return it if available (else return {@code null}).

spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ private static EntityManager createProxy(
232232

233233
if (emIfc != null) {
234234
interfaces = cachedEntityManagerInterfaces.computeIfAbsent(emIfc, key -> {
235-
Set<Class<?>> ifcs = new LinkedHashSet<>();
236-
ifcs.add(key);
237-
ifcs.add(EntityManagerProxy.class);
238-
return ClassUtils.toClassArray(ifcs);
235+
if (EntityManagerProxy.class.equals(key)) {
236+
return new Class[]{EntityManagerProxy.class};
237+
}
238+
return new Class<?>[]{key, EntityManagerProxy.class};
239239
});
240240
}
241241
else {

0 commit comments

Comments
 (0)