{"record":{"id":"5b981c6328adb47f","repo":"quarkusio/quarkus","slug":"unable-to-compare-null-operands-op1-op2-5b981c","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/WhenSectionHelper.java","lineNumber":261,"sourceCode":"                    return !Objects.equals(value, params.get(0));\n                case GE:\n                case GT:\n                case LE:\n                case LT:\n                    return compare(value, params.get(0));\n                case IN:\n                    return params.contains(value);\n                case NOT_IN:\n                    return !params.contains(value);\n                default:\n                    throw new TemplateException(\"Not a legal operator: \" + this);\n            }\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 = Operator.getDecimal(op1);\n                c2 = Operator.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":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/qute/core/src/main/java/io/quarkus/qute/WhenSectionHelper.java#L243-L279","documentation":"When a {when}/{if} comparison operator (e.g. >, >=) is evaluated and either operand is null, Qute cannot order the values and throws TemplateException from compare(). Equality-style checks handle null fine, but relational comparison of null is rejected deliberately rather than returning a silently wrong result.","triggerScenarios":"Evaluating expressions like {#when item.price > 10} or {#if a >= b} where item.price or b resolves to null (missing property, null value passed in the data map).","commonSituations":"Optional data not supplied to the template; properties absent on some objects in a collection; API/model changes that made a field nullable; forgetting the null-safe '?elvis' style access before comparing.","solutions":["Guard the comparison with a null check first, e.g. {#if item.price != null && item.price > 10}.","Use Qute's null-safe / default operators to coerce the operand, e.g. {item.price ?: 0} before comparing.","Provide non-null defaults in the data model when building the template data.","Restructure the {when} to compare only after an {#is} null check branch."],"exampleFix":"// before\n{#if order.discount > 0}...{/}\n// after\n{#if order.discount != null && order.discount > 0}...{/}\n// or\n{#if (order.discount ?: 0) > 0}...{/}","handlingStrategy":"validation","validationCode":"// in template\n{#if item.price != null && item.price > 10}...{/}\n// in Java before rendering\nObjects.requireNonNullElse(item.getPrice(), BigDecimal.ZERO);","typeGuard":"boolean isComparable(Object a, Object b) {\n    return a != null && b != null && a.getClass().equals(b.getClass()) && a instanceof Comparable;\n}","tryCatchPattern":"try {\n    renderTemplate(tpl, data);\n} catch (TemplateException e) {\n    if (e.getMessage().startsWith(\"Unable to compare null operands\")) {\n        // add null guards / defaults in the template or data model\n    }\n}","preventionTips":["Always guard relational comparisons with null checks in templates","Use the '?:' default operator to coerce possibly-null operands","Provide non-null defaults in the data model for optional fields"],"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-12T22:17:10.623Z"}