Nullability refinements and related polishing

See gh-32475
This commit is contained in:
Juergen Hoeller
2024-03-19 09:58:44 +01:00
parent cd7ba1835c
commit c531a8a705
58 changed files with 327 additions and 257 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -230,7 +230,7 @@ public class ConstructorReference extends SpelNodeImpl {
InlineList initializer = (InlineList) getChild(1);
sb.append("[] ").append(initializer.toStringAST());
}
else {
else if (this.dimensions != null) {
// new int[3], new java.lang.String[3][4], etc.
for (SpelNodeImpl dimension : this.dimensions) {
sb.append('[').append(dimension.toStringAST()).append(']');

View File

@@ -222,7 +222,9 @@ public class Indexer extends SpelNodeImpl {
}
if (this.indexedType == IndexedType.ARRAY) {
int insn = switch (this.exitTypeDescriptor) {
String exitTypeDescriptor = this.exitTypeDescriptor;
Assert.state(exitTypeDescriptor != null, "Array not compilable without descriptor");
int insn = switch (exitTypeDescriptor) {
case "D" -> {
mv.visitTypeInsn(CHECKCAST, "[D");
yield DALOAD;
@@ -258,8 +260,8 @@ public class Indexer extends SpelNodeImpl {
yield CALOAD;
}
default -> {
mv.visitTypeInsn(CHECKCAST, "["+ this.exitTypeDescriptor +
(CodeFlow.isPrimitiveArray(this.exitTypeDescriptor) ? "" : ";"));
mv.visitTypeInsn(CHECKCAST, "["+ exitTypeDescriptor +
(CodeFlow.isPrimitiveArray(exitTypeDescriptor) ? "" : ";"));
yield AALOAD;
}
};

View File

@@ -55,7 +55,7 @@ class Token {
* @param startPos the exact start position
* @param endPos the index of the last character
*/
Token(TokenKind tokenKind, char[] tokenData, int startPos, int endPos) {
Token(TokenKind tokenKind, @Nullable char[] tokenData, int startPos, int endPos) {
this.kind = tokenKind;
this.data = (tokenData != null ? new String(tokenData) : null);
this.startPos = startPos;

View File

@@ -296,7 +296,8 @@ public abstract class ReflectionHelper {
TypeDescriptor sourceType = TypeDescriptor.forObject(argument);
if (argument == null) {
// Perform the equivalent of GenericConversionService.convertNullSource() for a single argument.
if (targetType.getElementTypeDescriptor().getObjectType() == Optional.class) {
TypeDescriptor elementDesc = targetType.getElementTypeDescriptor();
if (elementDesc != null && elementDesc.getObjectType() == Optional.class) {
arguments[varargsPosition] = Optional.empty();
conversionOccurred = true;
}
@@ -383,7 +384,8 @@ public abstract class ReflectionHelper {
TypeDescriptor sourceType = TypeDescriptor.forObject(argument);
if (argument == null) {
// Perform the equivalent of GenericConversionService.convertNullSource() for a single argument.
if (varArgContentType.getElementTypeDescriptor().getObjectType() == Optional.class) {
TypeDescriptor elementDesc = varArgContentType.getElementTypeDescriptor();
if (elementDesc != null && elementDesc.getObjectType() == Optional.class) {
arguments[varargsPosition] = Optional.empty();
conversionOccurred = true;
}
@@ -408,7 +410,6 @@ public abstract class ReflectionHelper {
}
// Otherwise, convert remaining arguments to the varargs element type.
else {
Assert.state(varArgContentType != null, "No element type");
for (int i = varargsPosition; i < arguments.length; i++) {
Object argument = arguments[i];
arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), varArgContentType);