Skip to content

Commit db53586

Browse files
committed
Consistently use class literals for primitive types
To improve consistency and avoid confusion regarding primitive types and their wrapper types, this commit ensures that we always use class literals for primitive types. For example, instead of using the `Void.TYPE` constant, we now consistently use `void.class`.
1 parent 95a3f3b commit db53586

File tree

33 files changed

+231
-231
lines changed

33 files changed

+231
-231
lines changed

Diff for: integration-tests/src/test/java/org/springframework/expression/spel/support/BeanFactoryTypeConverter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -94,7 +94,7 @@ public boolean canConvert(TypeDescriptor sourceTypeDescriptor, TypeDescriptor ta
9494

9595
@Override
9696
public Object convertValue(Object value, TypeDescriptor sourceType, TypeDescriptor targetType) {
97-
if (targetType.getType() == Void.class || targetType.getType() == Void.TYPE) {
97+
if (targetType.getType() == Void.class || targetType.getType() == void.class) {
9898
return null;
9999
}
100100
if (conversionService.canConvert(sourceType, targetType)) {

Diff for: spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -417,7 +417,7 @@ private static Object processReturnType(
417417
returnValue = proxy;
418418
}
419419
Class<?> returnType = method.getReturnType();
420-
if (returnValue == null && returnType != Void.TYPE && returnType.isPrimitive()) {
420+
if (returnValue == null && returnType != void.class && returnType.isPrimitive()) {
421421
throw new AopInvocationException(
422422
"Null return value from advice does not match primitive return type for: " + method);
423423
}

Diff for: spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -230,7 +230,7 @@ else if (!this.advised.opaque && method.getDeclaringClass().isInterface() &&
230230
// a reference to itself in another returned object.
231231
retVal = proxy;
232232
}
233-
else if (retVal == null && returnType != Void.TYPE && returnType.isPrimitive()) {
233+
else if (retVal == null && returnType != void.class && returnType.isPrimitive()) {
234234
throw new AopInvocationException(
235235
"Null return value from advice does not match primitive return type for: " + method);
236236
}

Diff for: spring-aop/src/main/java/org/springframework/aop/support/Pointcuts.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -101,7 +101,7 @@ private static class SetterPointcut extends StaticMethodMatcherPointcut implemen
101101
public boolean matches(Method method, Class<?> targetClass) {
102102
return (method.getName().startsWith("set") &&
103103
method.getParameterCount() == 1 &&
104-
method.getReturnType() == Void.TYPE);
104+
method.getReturnType() == void.class);
105105
}
106106

107107
private Object readResolve() {
@@ -127,7 +127,7 @@ private static class GetterPointcut extends StaticMethodMatcherPointcut implemen
127127
public boolean matches(Method method, Class<?> targetClass) {
128128
return (method.getName().startsWith("get") &&
129129
method.getParameterCount() == 0 &&
130-
method.getReturnType() != Void.TYPE);
130+
method.getReturnType() != void.class);
131131
}
132132

133133
private Object readResolve() {

Diff for: spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -68,7 +68,7 @@ public static Collection<? extends PropertyDescriptor> determineBasicProperties(
6868
setter = true;
6969
nameIndex = 3;
7070
}
71-
else if (methodName.startsWith("get") && method.getParameterCount() == 0 && method.getReturnType() != Void.TYPE) {
71+
else if (methodName.startsWith("get") && method.getParameterCount() == 0 && method.getReturnType() != void.class) {
7272
setter = false;
7373
nameIndex = 3;
7474
}
@@ -152,7 +152,7 @@ public static Class<?> findPropertyType(@Nullable Method readMethod, @Nullable M
152152
throw new IntrospectionException("Bad read method arg count: " + readMethod);
153153
}
154154
propertyType = readMethod.getReturnType();
155-
if (propertyType == Void.TYPE) {
155+
if (propertyType == void.class) {
156156
throw new IntrospectionException("Read method returns void: " + readMethod);
157157
}
158158
}
@@ -197,11 +197,11 @@ public static Class<?> findIndexedPropertyType(String name, @Nullable Class<?> p
197197
if (params.length != 1) {
198198
throw new IntrospectionException("Bad indexed read method arg count: " + indexedReadMethod);
199199
}
200-
if (params[0] != Integer.TYPE) {
200+
if (params[0] != int.class) {
201201
throw new IntrospectionException("Non int index to indexed read method: " + indexedReadMethod);
202202
}
203203
indexedPropertyType = indexedReadMethod.getReturnType();
204-
if (indexedPropertyType == Void.TYPE) {
204+
if (indexedPropertyType == void.class) {
205205
throw new IntrospectionException("Indexed read method returns void: " + indexedReadMethod);
206206
}
207207
}
@@ -211,7 +211,7 @@ public static Class<?> findIndexedPropertyType(String name, @Nullable Class<?> p
211211
if (params.length != 2) {
212212
throw new IntrospectionException("Bad indexed write method arg count: " + indexedWriteMethod);
213213
}
214-
if (params[0] != Integer.TYPE) {
214+
if (params[0] != int.class) {
215215
throw new IntrospectionException("Non int index to indexed write method: " + indexedWriteMethod);
216216
}
217217
if (indexedPropertyType != null) {

Diff for: spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ public PointcutForVoid() {
698698
setPointcut(new DynamicMethodMatcherPointcut() {
699699
@Override
700700
public boolean matches(Method m, @Nullable Class<?> targetClass, Object... args) {
701-
return m.getReturnType() == Void.TYPE;
701+
return m.getReturnType() == void.class;
702702
}
703703
});
704704
}

Diff for: spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -107,7 +107,7 @@ private void registerReflectionHints(ReflectionHints hints, Set<Type> seen, Type
107107
if (methodName.startsWith("set") && method.getParameterCount() == 1) {
108108
registerPropertyHints(hints, seen, method, 0);
109109
}
110-
else if ((methodName.startsWith("get") && method.getParameterCount() == 0 && method.getReturnType() != Void.TYPE) ||
110+
else if ((methodName.startsWith("get") && method.getParameterCount() == 0 && method.getReturnType() != void.class) ||
111111
(methodName.startsWith("is") && method.getParameterCount() == 0 && method.getReturnType() == boolean.class)) {
112112
registerPropertyHints(hints, seen, method, -1);
113113
}

Diff for: spring-core/src/main/java/org/springframework/core/annotation/AnnotatedMethod.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public MethodParameter getReturnValueType(@Nullable Object returnValue) {
137137
* Return {@code true} if the method's return type is void, {@code false} otherwise.
138138
*/
139139
public boolean isVoid() {
140-
return Void.TYPE.equals(getReturnType().getParameterType());
140+
return (getReturnType().getParameterType() == void.class);
141141
}
142142

143143
/**

Diff for: spring-core/src/test/java/org/springframework/core/MethodParameterTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -52,7 +52,7 @@ class MethodParameterTests {
5252

5353
@BeforeEach
5454
void setup() throws NoSuchMethodException {
55-
method = getClass().getMethod("method", String.class, Long.TYPE);
55+
method = getClass().getMethod("method", String.class, long.class);
5656
stringParameter = new MethodParameter(method, 0);
5757
longParameter = new MethodParameter(method, 1);
5858
intReturnType = new MethodParameter(method, -1);
@@ -72,7 +72,7 @@ void equals() throws NoSuchMethodException {
7272
assertThat(intReturnType).isNotEqualTo(stringParameter);
7373
assertThat(intReturnType).isNotEqualTo(longParameter);
7474

75-
Method method = getClass().getMethod("method", String.class, Long.TYPE);
75+
Method method = getClass().getMethod("method", String.class, long.class);
7676
MethodParameter methodParameter = new MethodParameter(method, 0);
7777
assertThat(methodParameter).isEqualTo(stringParameter);
7878
assertThat(stringParameter).isEqualTo(methodParameter);
@@ -86,7 +86,7 @@ void testHashCode() throws NoSuchMethodException {
8686
assertThat(longParameter.hashCode()).isEqualTo(longParameter.hashCode());
8787
assertThat(intReturnType.hashCode()).isEqualTo(intReturnType.hashCode());
8888

89-
Method method = getClass().getMethod("method", String.class, Long.TYPE);
89+
Method method = getClass().getMethod("method", String.class, long.class);
9090
MethodParameter methodParameter = new MethodParameter(method, 0);
9191
assertThat(methodParameter.hashCode()).isEqualTo(stringParameter.hashCode());
9292
assertThat(methodParameter.hashCode()).isNotEqualTo(longParameter.hashCode());

Diff for: spring-core/src/test/java/org/springframework/core/annotation/SynthesizingMethodParameterTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -43,7 +43,7 @@ class SynthesizingMethodParameterTests {
4343

4444
@BeforeEach
4545
void setUp() throws NoSuchMethodException {
46-
method = getClass().getMethod("method", String.class, Long.TYPE);
46+
method = getClass().getMethod("method", String.class, long.class);
4747
stringParameter = new SynthesizingMethodParameter(method, 0);
4848
longParameter = new SynthesizingMethodParameter(method, 1);
4949
intReturnType = new SynthesizingMethodParameter(method, -1);
@@ -63,7 +63,7 @@ void equals() throws NoSuchMethodException {
6363
assertThat(intReturnType).isNotEqualTo(stringParameter);
6464
assertThat(intReturnType).isNotEqualTo(longParameter);
6565

66-
Method method = getClass().getMethod("method", String.class, Long.TYPE);
66+
Method method = getClass().getMethod("method", String.class, long.class);
6767
MethodParameter methodParameter = new SynthesizingMethodParameter(method, 0);
6868
assertThat(methodParameter).isEqualTo(stringParameter);
6969
assertThat(stringParameter).isEqualTo(methodParameter);
@@ -83,7 +83,7 @@ void testHashCode() throws NoSuchMethodException {
8383
assertThat(longParameter.hashCode()).isEqualTo(longParameter.hashCode());
8484
assertThat(intReturnType.hashCode()).isEqualTo(intReturnType.hashCode());
8585

86-
Method method = getClass().getMethod("method", String.class, Long.TYPE);
86+
Method method = getClass().getMethod("method", String.class, long.class);
8787
SynthesizingMethodParameter methodParameter = new SynthesizingMethodParameter(method, 0);
8888
assertThat(methodParameter.hashCode()).isEqualTo(stringParameter.hashCode());
8989
assertThat(methodParameter.hashCode()).isNotEqualTo(longParameter.hashCode());

Diff for: spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -303,7 +303,7 @@ void fieldListOfListUnknown() throws Exception {
303303
void fieldArray() throws Exception {
304304
TypeDescriptor typeDescriptor = new TypeDescriptor(TypeDescriptorTests.class.getDeclaredField("intArray"));
305305
assertThat(typeDescriptor.isArray()).isTrue();
306-
assertThat(typeDescriptor.getElementTypeDescriptor().getType()).isEqualTo(Integer.TYPE);
306+
assertThat(typeDescriptor.getElementTypeDescriptor().getType()).isEqualTo(int.class);
307307
assertThat(typeDescriptor.toString()).isEqualTo("int[]");
308308
}
309309

@@ -359,7 +359,7 @@ void valueOfPrimitive() {
359359
assertThat(typeDescriptor.isArray()).isFalse();
360360
assertThat(typeDescriptor.isCollection()).isFalse();
361361
assertThat(typeDescriptor.isMap()).isFalse();
362-
assertThat(typeDescriptor.getType()).isEqualTo(Integer.TYPE);
362+
assertThat(typeDescriptor.getType()).isEqualTo(int.class);
363363
assertThat(typeDescriptor.getObjectType()).isEqualTo(Integer.class);
364364
}
365365

@@ -369,7 +369,7 @@ void valueOfArray() {
369369
assertThat(typeDescriptor.isArray()).isTrue();
370370
assertThat(typeDescriptor.isCollection()).isFalse();
371371
assertThat(typeDescriptor.isMap()).isFalse();
372-
assertThat(typeDescriptor.getElementTypeDescriptor().getType()).isEqualTo(Integer.TYPE);
372+
assertThat(typeDescriptor.getElementTypeDescriptor().getType()).isEqualTo(int.class);
373373
}
374374

375375
@Test

Diff for: spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -454,31 +454,31 @@ public static String toJvmDescriptor(Class<?> clazz) {
454454
}
455455
}
456456
if (clazz.isPrimitive()) {
457-
if (clazz == Boolean.TYPE) {
457+
if (clazz == boolean.class) {
458458
sb.append('Z');
459459
}
460-
else if (clazz == Byte.TYPE) {
460+
else if (clazz == byte.class) {
461461
sb.append('B');
462462
}
463-
else if (clazz == Character.TYPE) {
463+
else if (clazz == char.class) {
464464
sb.append('C');
465465
}
466-
else if (clazz == Double.TYPE) {
466+
else if (clazz == double.class) {
467467
sb.append('D');
468468
}
469-
else if (clazz == Float.TYPE) {
469+
else if (clazz == float.class) {
470470
sb.append('F');
471471
}
472-
else if (clazz == Integer.TYPE) {
472+
else if (clazz == int.class) {
473473
sb.append('I');
474474
}
475-
else if (clazz == Long.TYPE) {
475+
else if (clazz == long.class) {
476476
sb.append('J');
477477
}
478-
else if (clazz == Short.TYPE) {
478+
else if (clazz == short.class) {
479479
sb.append('S');
480480
}
481-
else if (clazz == Void.TYPE) {
481+
else if (clazz == void.class) {
482482
sb.append('V');
483483
}
484484
}

Diff for: spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -385,49 +385,49 @@ else if (arrayComponentType == short.class) {
385385

386386
private Object accessArrayElement(Object ctx, int idx) throws SpelEvaluationException {
387387
Class<?> arrayComponentType = ctx.getClass().componentType();
388-
if (arrayComponentType == Boolean.TYPE) {
388+
if (arrayComponentType == boolean.class) {
389389
boolean[] array = (boolean[]) ctx;
390390
checkAccess(array.length, idx);
391391
this.exitTypeDescriptor = "Z";
392392
return array[idx];
393393
}
394-
else if (arrayComponentType == Byte.TYPE) {
394+
else if (arrayComponentType == byte.class) {
395395
byte[] array = (byte[]) ctx;
396396
checkAccess(array.length, idx);
397397
this.exitTypeDescriptor = "B";
398398
return array[idx];
399399
}
400-
else if (arrayComponentType == Character.TYPE) {
400+
else if (arrayComponentType == char.class) {
401401
char[] array = (char[]) ctx;
402402
checkAccess(array.length, idx);
403403
this.exitTypeDescriptor = "C";
404404
return array[idx];
405405
}
406-
else if (arrayComponentType == Double.TYPE) {
406+
else if (arrayComponentType == double.class) {
407407
double[] array = (double[]) ctx;
408408
checkAccess(array.length, idx);
409409
this.exitTypeDescriptor = "D";
410410
return array[idx];
411411
}
412-
else if (arrayComponentType == Float.TYPE) {
412+
else if (arrayComponentType == float.class) {
413413
float[] array = (float[]) ctx;
414414
checkAccess(array.length, idx);
415415
this.exitTypeDescriptor = "F";
416416
return array[idx];
417417
}
418-
else if (arrayComponentType == Integer.TYPE) {
418+
else if (arrayComponentType == int.class) {
419419
int[] array = (int[]) ctx;
420420
checkAccess(array.length, idx);
421421
this.exitTypeDescriptor = "I";
422422
return array[idx];
423423
}
424-
else if (arrayComponentType == Long.TYPE) {
424+
else if (arrayComponentType == long.class) {
425425
long[] array = (long[]) ctx;
426426
checkAccess(array.length, idx);
427427
this.exitTypeDescriptor = "J";
428428
return array[idx];
429429
}
430-
else if (arrayComponentType == Short.TYPE) {
430+
else if (arrayComponentType == short.class) {
431431
short[] array = (short[]) ctx;
432432
checkAccess(array.length, idx);
433433
this.exitTypeDescriptor = "S";

0 commit comments

Comments
 (0)