Throw IllegalArgumentException for null Criteria literal value

This commit is contained in:
Andrea Boriero 2022-01-13 18:34:27 +01:00 committed by Andrea Boriero
parent fb17eb52df
commit 9fba739bc2
2 changed files with 34 additions and 0 deletions

View File

@ -914,6 +914,9 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
@Override @Override
public <T> SqmLiteral<T> literal(T value) { public <T> SqmLiteral<T> literal(T value) {
if ( value == null ) { if ( value == null ) {
if ( jpaComplianceEnabled ) {
throw new IllegalArgumentException( "literal value cannot be null" );
}
return new SqmLiteralNull<>( this ); return new SqmLiteralNull<>( this );
} }

View File

@ -0,0 +1,31 @@
package org.hibernate.orm.test.jpa.compliance;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import jakarta.persistence.criteria.CriteriaBuilder;
import static org.junit.jupiter.api.Assertions.fail;
@Jpa(
properties = @Setting(name = AvailableSettings.JPA_QUERY_COMPLIANCE, value = "true")
)
public class CriteriaLiteralValue {
@Test
public void testLiteralValueCannotBeNull(EntityManagerFactoryScope scope) {
final CriteriaBuilder builder = scope.getEntityManagerFactory().getCriteriaBuilder();
try {
builder.literal(null);
fail( "TCK expects an IllegalArgumentException" );
} catch (IllegalArgumentException iae) {
// //expected by TCK
}
}
}