HHH-17807 fix NPE in array argument validation

probably only occurs when the argument is a parameter
This commit is contained in:
Gavin King 2024-03-05 17:55:09 +01:00
parent 691a2d8109
commit 5a7661be5c
2 changed files with 23 additions and 14 deletions

View File

@ -50,21 +50,27 @@ public class ArrayArgumentValidator implements ArgumentsValidator {
String functionName,
TypeConfiguration typeConfiguration) {
final SqmTypedNode<?> arrayArgument = arguments.get( arrayIndex );
final SqmExpressible<?> arrayType = arrayArgument.getExpressible().getSqmType();
if ( arrayType == null ) {
final SqmExpressible<?> expressible = arrayArgument.getExpressible();
if ( expressible == null ) {
return null;
}
else if ( !( arrayType instanceof BasicPluralType<?, ?> ) ) {
throw new FunctionArgumentException(
String.format(
"Parameter %d of function '%s()' requires an array type, but argument is of type '%s'",
arrayIndex,
functionName,
arrayType.getTypeName()
)
);
else {
final SqmExpressible<?> arrayType = expressible.getSqmType();
if ( arrayType == null ) {
return null;
}
else if ( !( arrayType instanceof BasicPluralType<?, ?> ) ) {
throw new FunctionArgumentException(
String.format(
"Parameter %d of function '%s()' requires an array type, but argument is of type '%s'",
arrayIndex,
functionName,
arrayType.getTypeName()
)
);
}
return (BasicPluralType<?, ?>) arrayType;
}
return (BasicPluralType<?, ?>) arrayType;
}
protected BasicType<?> getElementType(

View File

@ -31,10 +31,13 @@ public class ArrayContainsArgumentValidator extends ArrayArgumentValidator {
List<? extends SqmTypedNode<?>> arguments,
String functionName,
TypeConfiguration typeConfiguration) {
final BasicPluralType<?, ?> haystackType = getPluralType( 0, arguments, functionName, typeConfiguration );
final BasicPluralType<?, ?> haystackType =
getPluralType( 0, arguments, functionName, typeConfiguration );
final SqmExpressible<?> expressible = arguments.get( 1 ).getExpressible();
final SqmExpressible<?> needleType = expressible == null ? null : expressible.getSqmType();
if ( needleType != null && !haystackType.equals( needleType ) && !haystackType.getElementType().equals( needleType ) ) {
if ( haystackType!= null && needleType != null
&& !haystackType.equals( needleType )
&& !haystackType.getElementType().equals( needleType ) ) {
throw new FunctionArgumentException(
String.format(
"Parameter 1 of function '%s()' has type %s, but argument is of type '%s'",