Expressions.asBoolean(boolean) cannot be used with BooleanExpression.and(Predicate) #2063

thomas-dorka opened this Issue Dec 14, 2016 · 1 comment


None yet

1 participant

thomas-dorka commented Dec 14, 2016 edited

querydsl-core 4.1.4

to reproduce:

    final BooleanExpression falseBE = Expressions.asBoolean (false);
    final BooleanExpression trueBE = Expressions.asBoolean (true);
    falseBE.and (trueBE);


java.lang.ClassCastException: com.querydsl.core.types.ConstantImpl cannot be cast to com.querydsl.core.types.Predicate
	at com.querydsl.core.types.dsl.BooleanExpression.and(

NB: this works:

    final BooleanExpression falseBE = Expressions.FALSE;
    final BooleanExpression trueBE = Expressions.TRUE;
    falseBE.and (trueBE);
thomas-dorka commented Dec 15, 2016 edited

This fixes the issue, but I'm not sure whether it's the right solution to the problem.

public abstract class BooleanExpression extends LiteralExpression<Boolean> implements Predicate {


    public BooleanExpression and(@Nullable Predicate right) {
        Expression<Boolean> expression = ExpressionUtils.extract(right);
        if (expression != null) {
            return Expressions.booleanOperation(Ops.AND, mixin, expression);
        } else {
            return this;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment