{"record":{"id":"8a26d857919e3e34","repo":"quarkusio/quarkus","slug":"unable-to-compare-null-operands-op1-op2","errorCode":null,"errorMessage":"Unable to compare null operands [op1=, op2=]","messagePattern":"Unable to compare null operands \\[op1=, op2=\\]","errorType":"exception","errorClass":"TemplateException","httpStatus":null,"severity":"error","filePath":"independent-projects/qute/core/src/main/java/io/quarkus/qute/IfSectionHelper.java","lineNumber":510,"sourceCode":"                    throw new TemplateException(\"Not a binary operator: \" + this);\n            }\n        }\n\n        boolean equals(Object op1, Object op2) {\n            if (Objects.equals(op1, op2)) {\n                return true;\n            }\n            if (op1 != null && op2 != null && (op1 instanceof Number || op2 instanceof Number)) {\n                // Both operands are not null and at least one of them is a number\n                return getDecimal(op1).compareTo(getDecimal(op2)) == 0;\n            }\n            return false;\n        }\n\n        @SuppressWarnings({ \"rawtypes\", \"unchecked\" })\n        boolean compare(Object op1, Object op2) {\n            if (op1 == null || op2 == null) {\n                throw new TemplateException(\"Unable to compare null operands [op1=\" + op1 + \", op2=\" + op2 + \"]\");\n            }\n            Comparable c1;\n            Comparable c2;\n            if (op1 instanceof Comparable && op1.getClass().equals(op2.getClass())) {\n                c1 = (Comparable) op1;\n                c2 = (Comparable) op2;\n            } else {\n                c1 = getDecimal(op1);\n                c2 = getDecimal(op2);\n            }\n            int result = c1.compareTo(c2);\n            switch (this) {\n                case GE:\n                    return result >= 0;\n                case GT:\n                    return result > 0;\n                case LE:\n                    return result <= 0;","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/qute/core/src/main/java/io/quarkus/qute/IfSectionHelper.java#L492-L528","documentation":"IfSectionHelper.compare() is used for <, >, <=, >= comparisons in {#if} blocks. It throws TemplateException(\"Unable to compare null operands [op1=..., op2=...]\") when either operand is null, since null ordering is undefined in Qute comparisons.","triggerScenarios":"An {#if} expression like {#if item.price > 10} or {#if date1 le date2} where one side resolves to null at evaluation time.","commonSituations":"Optional/missing model properties not initialized; config values absent; query results null; nullable dates compared against a constant.","solutions":["Guard the comparison with an existence check: {#if item.price != null && item.price > 10} or use the elvis operator (item.price ?: 0).","Provide a default value in the model so the operand is never null.","Use ==/!= (which handle null) instead of ordering operators when null is possible."],"exampleFix":"// before\n{#if order.date > cutoffDate} // order.date is null -> TemplateException\n// after\n{#if order.date != null && order.date > cutoffDate}","handlingStrategy":"validation","validationCode":"// in template\n{#if order.date != null && order.date > cutoffDate}\n// or in model\nObjects.requireNonNullElse(order.getDate(), Instant.EPOCH);","typeGuard":"boolean comparableValues(Object a, Object b) {\n    return a != null && b != null\n        && a instanceof Comparable && a.getClass().equals(b.getClass());\n}","tryCatchPattern":"try {\n    return condition.evaluate(ctx);\n} catch (TemplateException ex) {\n    if (ex.getMessage().startsWith(\"Unable to compare null operands\")) {\n        LOGGER.warn(\"null operand in {#if} comparison: {}\", ex.getMessage());\n        return false; // or rethrow after logging\n    }\n    throw ex;\n}","preventionTips":["Null-check operands before <, >, <=, >= in {#if} expressions","Use elvis (?:) to supply defaults for possibly-null operands","Initialize model/config properties used in ordered comparisons","Prefer ==/!= (null-safe) when ordering is not required"],"tags":["qute","template","null","comparison"],"backgroundTag":"null-operand-comparison","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}