Skip to content

Commit 0cb4043

Browse files
committed
Polishing
1 parent 6030e62 commit 0cb4043

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,9 @@ public static boolean isBooleanCompatible(@Nullable String descriptor) {
515515
}
516516

517517
/**
518-
* Determine whether the descriptor is for a primitive type.
518+
* Determine whether the descriptor is for a primitive type or {@code void}.
519519
* @param descriptor type descriptor
520-
* @return {@code true} if a primitive type
520+
* @return {@code true} if a primitive type or {@code void}
521521
*/
522522
public static boolean isPrimitive(@Nullable String descriptor) {
523523
return (descriptor != null && descriptor.length() == 1);

spring-expression/src/main/java/org/springframework/expression/spel/ast/MethodReference.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class MethodReference extends SpelNodeImpl {
6060
private final String name;
6161

6262
@Nullable
63-
private String originalPrimitiveExitTypeDescriptor;
63+
private Character originalPrimitiveExitTypeDescriptor;
6464

6565
@Nullable
6666
private volatile CachedMethodExecutor cachedExecutor;
@@ -260,7 +260,7 @@ private void updateExitTypeDescriptor() {
260260
Method method = reflectiveMethodExecutor.getMethod();
261261
String descriptor = CodeFlow.toDescriptor(method.getReturnType());
262262
if (this.nullSafe && CodeFlow.isPrimitive(descriptor)) {
263-
this.originalPrimitiveExitTypeDescriptor = descriptor;
263+
this.originalPrimitiveExitTypeDescriptor = descriptor.charAt(0);
264264
this.exitTypeDescriptor = CodeFlow.toBoxedDescriptor(descriptor);
265265
}
266266
else {

spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -184,8 +184,9 @@ private Class<? extends CompiledExpression> createExpressionClass(SpelNodeImpl e
184184
cf.finish();
185185

186186
byte[] data = cw.toByteArray();
187-
// TODO need to make this conditionally occur based on a debug flag
188-
// dump(expressionToCompile.toStringAST(), clazzName, data);
187+
// TODO Save generated class files conditionally based on a debug flag.
188+
// Source code for the following method resides in SpelCompilationCoverageTests.
189+
// saveGeneratedClassFile(expressionToCompile.toStringAST(), className, data);
189190
return loadClass(StringUtils.replace(className, "/", "."), data);
190191
}
191192

spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6255,4 +6255,19 @@ public void setValue2(Integer value) {
62556255
}
62566256
}
62576257

6258+
// NOTE: saveGeneratedClassFile() can be copied to SpelCompiler and uncommented
6259+
// at the end of createExpressionClass(SpelNodeImpl) in order to review generated
6260+
// byte code for debugging purposes.
6261+
//
6262+
// private static void saveGeneratedClassFile(String stringAST, String className, byte[] data) {
6263+
// Path path = Path.of("build", StringUtils.replace(className, "/", ".") + ".class");
6264+
// System.out.println("Writing compiled SpEL expression [%s] to [%s]".formatted(stringAST, path.toAbsolutePath()));
6265+
// try {
6266+
// Files.copy(new ByteArrayInputStream(data), path);
6267+
// }
6268+
// catch (IOException ex) {
6269+
// throw new UncheckedIOException(ex);
6270+
// }
6271+
// }
6272+
62586273
}

0 commit comments

Comments
 (0)