HHH-17729 move validation of constructors in HQL instantiations to SemanticQueryBuilder

also validate injection via fields/properties
This commit is contained in:
Gavin King 2024-02-11 17:16:47 +01:00
parent dcb2c60d4e
commit a9ea331e40
2 changed files with 5 additions and 5 deletions

View File

@ -143,7 +143,7 @@ public class SqmDynamicInstantiation<T>
private List<Class<?>> argumentTypes() {
return getArguments().stream()
.map(arg -> arg.getNodeJavaType().getJavaTypeClass())
.map(arg -> arg.getNodeJavaType() == null ? Void.class : arg.getNodeJavaType().getJavaTypeClass())
.collect(toList());
}

View File

@ -53,7 +53,7 @@ public class InstantiationHelper {
return true;
}
}
return findField(targetJavaType, alias, argType) != null;
return findField( targetJavaType, alias, argType ) != null;
}
public static boolean isConstructorCompatible(Class<?> javaClass, List<Class<?>> argTypes, TypeConfiguration typeConfiguration) {
@ -74,11 +74,11 @@ public class InstantiationHelper {
for (int i = 0; i < argumentTypes.size(); i++ ) {
final Type parameterType = genericParameterTypes[i];
final Class<?> argumentType = argumentTypes.get( i );
final Class<?> argType = parameterType instanceof Class<?>
final Class<?> type = parameterType instanceof Class<?>
? (Class<?>) parameterType
: typeConfiguration.getJavaTypeRegistry().resolveDescriptor( parameterType ).getJavaTypeClass();
if ( !areAssignmentCompatible( argType, argumentType ) ) {
if ( !areAssignmentCompatible( type, argumentType ) ) {
if ( log.isDebugEnabled() ) {
log.debugf(
"Skipping constructor for dynamic-instantiation match due to argument mismatch [%s] : %s -> %s",
@ -116,7 +116,7 @@ public class InstantiationHelper {
}
static boolean propertyMatches(String alias, Class<?> argType, PropertyDescriptor propertyDescriptor) {
return alias.equals(propertyDescriptor.getName())
return alias.equals( propertyDescriptor.getName() )
&& propertyDescriptor.getWriteMethod() != null
&& areAssignmentCompatible( propertyDescriptor.getWriteMethod().getParameterTypes()[0], argType );
}