Consistently invoke isNullSafe()

This commit is contained in:
Sam Brannen 2025-03-07 14:18:56 +01:00
parent 80df88bd4f
commit 86d81632c8
4 changed files with 11 additions and 11 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -166,7 +166,7 @@ public class Indexer extends SpelNodeImpl {
Object target = context.getValue(); Object target = context.getValue();
if (target == null) { if (target == null) {
if (this.nullSafe) { if (isNullSafe()) {
return ValueRef.NullValueRef.INSTANCE; return ValueRef.NullValueRef.INSTANCE;
} }
// Raise a proper exception in case of a null target // Raise a proper exception in case of a null target
@ -330,7 +330,7 @@ public class Indexer extends SpelNodeImpl {
} }
Label skipIfNull = null; Label skipIfNull = null;
if (this.nullSafe) { if (isNullSafe()) {
mv.visitInsn(DUP); mv.visitInsn(DUP);
skipIfNull = new Label(); skipIfNull = new Label();
Label continueLabel = new Label(); Label continueLabel = new Label();
@ -439,7 +439,7 @@ public class Indexer extends SpelNodeImpl {
// If this indexer would return a primitive - and yet it is also marked // If this indexer would return a primitive - and yet it is also marked
// null-safe - then the exit type descriptor must be promoted to the box // null-safe - then the exit type descriptor must be promoted to the box
// type to allow a null value to be passed on. // type to allow a null value to be passed on.
if (this.nullSafe && CodeFlow.isPrimitive(descriptor)) { if (isNullSafe() && CodeFlow.isPrimitive(descriptor)) {
this.originalPrimitiveExitTypeDescriptor = descriptor; this.originalPrimitiveExitTypeDescriptor = descriptor;
this.exitTypeDescriptor = CodeFlow.toBoxedDescriptor(descriptor); this.exitTypeDescriptor = CodeFlow.toBoxedDescriptor(descriptor);
} }

View File

@ -160,7 +160,7 @@ public class MethodReference extends SpelNodeImpl {
} }
private void throwIfNotNullSafe(List<TypeDescriptor> argumentTypes) { private void throwIfNotNullSafe(List<TypeDescriptor> argumentTypes) {
if (!this.nullSafe) { if (!isNullSafe()) {
throw new SpelEvaluationException(getStartPosition(), throw new SpelEvaluationException(getStartPosition(),
SpelMessage.METHOD_CALL_ON_NULL_OBJECT_NOT_ALLOWED, SpelMessage.METHOD_CALL_ON_NULL_OBJECT_NOT_ALLOWED,
FormatHelper.formatMethodForMessage(this.name, argumentTypes)); FormatHelper.formatMethodForMessage(this.name, argumentTypes));
@ -258,7 +258,7 @@ public class MethodReference extends SpelNodeImpl {
if (executorToCheck != null && executorToCheck.get() instanceof ReflectiveMethodExecutor reflectiveMethodExecutor) { if (executorToCheck != null && executorToCheck.get() instanceof ReflectiveMethodExecutor reflectiveMethodExecutor) {
Method method = reflectiveMethodExecutor.getMethod(); Method method = reflectiveMethodExecutor.getMethod();
String descriptor = CodeFlow.toDescriptor(method.getReturnType()); String descriptor = CodeFlow.toDescriptor(method.getReturnType());
if (this.nullSafe && CodeFlow.isPrimitive(descriptor) && (descriptor.charAt(0) != 'V')) { if (isNullSafe() && CodeFlow.isPrimitive(descriptor) && (descriptor.charAt(0) != 'V')) {
this.originalPrimitiveExitTypeDescriptor = descriptor.charAt(0); this.originalPrimitiveExitTypeDescriptor = descriptor.charAt(0);
this.exitTypeDescriptor = CodeFlow.toBoxedDescriptor(descriptor); this.exitTypeDescriptor = CodeFlow.toBoxedDescriptor(descriptor);
} }
@ -324,7 +324,7 @@ public class MethodReference extends SpelNodeImpl {
} }
Label skipIfNull = null; Label skipIfNull = null;
if (this.nullSafe && (descriptor != null || !isStatic)) { if (isNullSafe() && (descriptor != null || !isStatic)) {
skipIfNull = new Label(); skipIfNull = new Label();
Label continueLabel = new Label(); Label continueLabel = new Label();
mv.visitInsn(DUP); mv.visitInsn(DUP);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -131,7 +131,7 @@ public class Projection extends SpelNodeImpl {
} }
if (operand == null) { if (operand == null) {
if (this.nullSafe) { if (isNullSafe()) {
return ValueRef.NullValueRef.INSTANCE; return ValueRef.NullValueRef.INSTANCE;
} }
throw new SpelEvaluationException(getStartPosition(), SpelMessage.PROJECTION_NOT_SUPPORTED_ON_TYPE, "null"); throw new SpelEvaluationException(getStartPosition(), SpelMessage.PROJECTION_NOT_SUPPORTED_ON_TYPE, "null");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -199,7 +199,7 @@ public class Selection extends SpelNodeImpl {
} }
if (operand == null) { if (operand == null) {
if (this.nullSafe) { if (isNullSafe()) {
return ValueRef.NullValueRef.INSTANCE; return ValueRef.NullValueRef.INSTANCE;
} }
throw new SpelEvaluationException(getStartPosition(), SpelMessage.INVALID_TYPE_FOR_SELECTION, "null"); throw new SpelEvaluationException(getStartPosition(), SpelMessage.INVALID_TYPE_FOR_SELECTION, "null");