Skip to content

Specification.not() fails with NullPointerException when other Specification returns null #3849

Closed
@SWQXDBA

Description

@SWQXDBA
/**
	 * Negates the given {@link Specification}.
	 *
	 * @param <T> the type of the {@link Root} the resulting {@literal Specification} operates on.
	 * @param spec can be {@literal null}.
	 * @return guaranteed to be not {@literal null}.
	 * @since 2.0
	 */
	static <T> Specification<T> not(@Nullable Specification<T> spec) {

		return spec == null //
				? (root, query, builder) -> null //
				: (root, query, builder) -> builder.not(spec.toPredicate(root, query, builder));
	}

Cannot invoke "org.hibernate.query.sqm.tree.expression.SqmExpression.getExpressible()" because "booleanExpression" is null\njava.lang.NullPointerException: Cannot invoke "org.hibernate.query.sqm.tree.expression.SqmExpression.getExpressible()" because "booleanExpression" is null
at org.hibernate.query.sqm.tree.predicate.SqmBooleanExpressionPredicate.(SqmBooleanExpressionPredicate.java:38)
at org.hibernate.query.sqm.tree.predicate.SqmBooleanExpressionPredicate.(SqmBooleanExpressionPredicate.java:31)
at org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder.wrap(SqmCriteriaNodeBuilder.java:497)
at org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder.not(SqmCriteriaNodeBuilder.java:2088)
at org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder.not(SqmCriteriaNodeBuilder.java:192)
at org.springframework.data.jpa.domain.Specification.lambda$1(Specification.java:58)
at org.springframework.data.jpa.domain.SpecificationComposition.toPredicate(SpecificationComposition.java:62)
at org.springframework.data.jpa.domain.SpecificationComposition.lambda$0(SpecificationComposition.java:49)
at org.springframework.data.jpa.domain.SpecificationComposition.toPredicate(SpecificationComposition.java:62)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions