{"record":{"id":"cc358f4449bc3e74","repo":"quarkusio/quarkus","slug":"literal-must-not-be-null","errorCode":null,"errorMessage":"Literal must not be null","messagePattern":"Literal must not be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/qute/core/src/main/java/io/quarkus/qute/ExpressionImpl.java","lineNumber":38,"sourceCode":"     */\n    static ExpressionImpl from(String value) {\n        if (value == null || value.isEmpty()) {\n            return EMPTY;\n        }\n        return Parser.parseExpression(ExpressionImpl::syntheticId, value, Scope.EMPTY, Parser.SYNTHETIC_ORIGIN);\n    }\n\n    static ExpressionImpl literalFrom(int id, String literal) {\n        if (literal == null || literal.isEmpty()) {\n            return EMPTY;\n        }\n        Object literalValue = LiteralSupport.getLiteralValue(literal);\n        return literal(id, literal, literalValue, Parser.SYNTHETIC_ORIGIN);\n    }\n\n    static ExpressionImpl literal(int id, String literal, Object value, Origin origin) {\n        if (literal == null) {\n            throw new IllegalArgumentException(\"Literal must not be null\");\n        }\n        String typeInfo = null;\n        if (value != null) {\n            typeInfo = Expressions.typeInfoFrom(value.getClass().getName());\n        }\n        return new ExpressionImpl(id, null, List.of(new PartImpl(literal, typeInfo)), value, origin);\n    }\n\n    static Integer syntheticId() {\n        return -1;\n    }\n\n    private final int id;\n    private final String namespace;\n    private final List<Part> parts;\n    private final CompletedStage<Object> literal;\n    private final Origin origin;\n","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/qute/core/src/main/java/io/quarkus/qute/ExpressionImpl.java#L20-L56","documentation":"ExpressionImpl.literal() builds a literal Qute expression from a string and throws this IllegalArgumentException when the literal string is null. The library treats a null literal as a programming error because a literal expression must carry at least the raw text it represents. The public entry point literal(id, literal) computes the value via LiteralSupport.getLiteralValue(literal), which itself requires a non-null input.","triggerScenarios":"Calling ExpressionImpl.literal(int id, String literal) or literalFrom(...) with a null literal argument, or passing null text derived from parsing (e.g. a parser/synthetic expression built with a null token).","commonSituations":"Custom template parsers or tooling that constructs synthetic literal expressions; passing a variable holding template text that was never initialized; reflection-based code building expressions where a token lookup returned null.","solutions":["Check the literal string for null before calling literal()/literalFrom() and substitute an empty string or skip the expression.","If the value is genuinely absent, build the expression with the value-only overload instead of a null literal text.","Trace back where the null token came from — usually an upstream parse or lookup that produced null unexpectedly."],"exampleFix":"// before\nString text = maybeNull();\nExpression e = ExpressionImpl.literal(1, text);\n// after\nString text = maybeNull();\nif (text == null) {\n    text = \"\"; // or skip creating the expression\n}\nExpression e = ExpressionImpl.literal(1, text);","handlingStrategy":"validation","validationCode":"if (literalText == null) {\n    throw new IllegalArgumentException(\"literal text required\");\n}\nExpression e = ExpressionImpl.literal(id, literalText);","typeGuard":"boolean isValidLiteral(String s) { return s != null; }","tryCatchPattern":"try {\n    Expression e = ExpressionImpl.literal(id, text);\n} catch (IllegalArgumentException ex) {\n    // fall back to empty/synthetic expression\n}","preventionTips":["Never pass possibly-null strings into expression builder APIs","Coerce nulls to empty strings at the parse boundary","Add a null check assertion in custom parser code before building literal expressions"],"tags":["qute","template","illegal-argument","null-check"],"backgroundTag":"null-argument-passed","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"}