Skip to content

Commit c356ce2

Browse files
committed
Polishing
1 parent 9f8293b commit c356ce2

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,20 +314,22 @@ public void generateCode(MethodVisitor mv, CodeFlow cf) {
314314
boolean isStaticMethod = Modifier.isStatic(method.getModifiers());
315315
String descriptor = cf.lastDescriptor();
316316

317-
Label skipIfNull = null;
318317
if (descriptor == null && !isStaticMethod) {
319318
// Nothing on the stack but something is needed
320319
cf.loadTarget(mv);
321320
}
322-
if ((descriptor != null || !isStaticMethod) && this.nullSafe) {
323-
mv.visitInsn(DUP);
321+
322+
Label skipIfNull = null;
323+
if (this.nullSafe && (descriptor != null || !isStaticMethod)) {
324324
skipIfNull = new Label();
325325
Label continueLabel = new Label();
326+
mv.visitInsn(DUP);
326327
mv.visitJumpInsn(IFNONNULL, continueLabel);
327328
CodeFlow.insertCheckCast(mv, this.exitTypeDescriptor);
328329
mv.visitJumpInsn(GOTO, skipIfNull);
329330
mv.visitLabel(continueLabel);
330331
}
332+
331333
if (descriptor != null && isStaticMethod) {
332334
// Something on the stack when nothing is needed
333335
mv.visitInsn(POP);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6429,10 +6429,11 @@ public void setValue2(Integer value) {
64296429
// at the end of createExpressionClass(SpelNodeImpl) in order to review generated
64306430
// byte code for debugging purposes.
64316431
//
6432-
// private static void saveGeneratedClassFile(String stringAST, String className, byte[] data) {
6433-
// Path path = Path.of("build", StringUtils.replace(className, "/", ".") + ".class");
6434-
// System.out.println("Writing compiled SpEL expression [%s] to [%s]".formatted(stringAST, path.toAbsolutePath()));
6432+
// private static void saveGeneratedClassFile(String stringAST, String className, byte[] data) {
64356433
// try {
6434+
// Path path = Path.of("build", StringUtils.replace(className, "/", ".") + ".class");
6435+
// Files.deleteIfExists(path);
6436+
// System.out.println("Writing compiled SpEL expression [%s] to [%s]".formatted(stringAST, path.toAbsolutePath()));
64366437
// Files.copy(new ByteArrayInputStream(data), path);
64376438
// }
64386439
// catch (IOException ex) {

0 commit comments

Comments
 (0)