Browse Source

Polishing

pull/31346/head
Sam Brannen 2 years ago
parent
commit
c356ce2637
  1. 8
      spring-expression/src/main/java/org/springframework/expression/spel/ast/MethodReference.java
  2. 3
      spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java

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

@ -314,20 +314,22 @@ public class MethodReference extends SpelNodeImpl { @@ -314,20 +314,22 @@ public class MethodReference extends SpelNodeImpl {
boolean isStaticMethod = Modifier.isStatic(method.getModifiers());
String descriptor = cf.lastDescriptor();
Label skipIfNull = null;
if (descriptor == null && !isStaticMethod) {
// Nothing on the stack but something is needed
cf.loadTarget(mv);
}
if ((descriptor != null || !isStaticMethod) && this.nullSafe) {
mv.visitInsn(DUP);
Label skipIfNull = null;
if (this.nullSafe && (descriptor != null || !isStaticMethod)) {
skipIfNull = new Label();
Label continueLabel = new Label();
mv.visitInsn(DUP);
mv.visitJumpInsn(IFNONNULL, continueLabel);
CodeFlow.insertCheckCast(mv, this.exitTypeDescriptor);
mv.visitJumpInsn(GOTO, skipIfNull);
mv.visitLabel(continueLabel);
}
if (descriptor != null && isStaticMethod) {
// Something on the stack when nothing is needed
mv.visitInsn(POP);

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

@ -6430,9 +6430,10 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { @@ -6430,9 +6430,10 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
// byte code for debugging purposes.
//
// private static void saveGeneratedClassFile(String stringAST, String className, byte[] data) {
// try {
// Path path = Path.of("build", StringUtils.replace(className, "/", ".") + ".class");
// Files.deleteIfExists(path);
// System.out.println("Writing compiled SpEL expression [%s] to [%s]".formatted(stringAST, path.toAbsolutePath()));
// try {
// Files.copy(new ByteArrayInputStream(data), path);
// }
// catch (IOException ex) {

Loading…
Cancel
Save