Polishing

This commit is contained in:
Sam Brannen
2023-10-01 16:32:29 +02:00
parent 9f8293b9c9
commit c356ce2637
2 changed files with 9 additions and 6 deletions

View File

@@ -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);

View File

@@ -6429,10 +6429,11 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
// at the end of createExpressionClass(SpelNodeImpl) in order to review generated
// byte code for debugging purposes.
//
// private static void saveGeneratedClassFile(String stringAST, String className, byte[] data) {
// Path path = Path.of("build", StringUtils.replace(className, "/", ".") + ".class");
// System.out.println("Writing compiled SpEL expression [%s] to [%s]".formatted(stringAST, path.toAbsolutePath()));
// 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()));
// Files.copy(new ByteArrayInputStream(data), path);
// }
// catch (IOException ex) {