quarkusio/quarkus · error · RuntimeException

Invalid template

Error message

Invalid template

What it means

DevUIContent.Builder.template(byte[]) throws this when the template byte array is null or empty. The builder requires actual template bytes because the Dev UI page content is generated from this template at build time; a null/empty template would produce a broken page.

Source

Thrown at extensions/devui/deployment-spi/src/main/java/io/quarkus/devui/spi/DevUIContent.java:76

        private Map<String, String> descriptions;
        private Map<String, String> contentTypes;
        private Map<String, String> mcpDefaultEnabled;

        private Builder() {
            this.data = new HashMap<>();
        }

        public Builder fileName(String fileName) {
            if (fileName == null || fileName.isEmpty()) {
                throw new RuntimeException("Invalid fileName");
            }
            this.fileName = fileName;
            return this;
        }

        public Builder template(byte[] template) {
            if (template == null || template.length == 0) {
                throw new RuntimeException("Invalid template");
            }

            this.template = template;
            return this;
        }

        public Builder addData(Map<String, Object> data) {
            this.data.putAll(data);
            return this;
        }

        public Builder addData(String key, Object value) {
            this.data.put(key, value);
            return this;
        }

        public Builder descriptions(Map<String, String> descriptions) {
            this.descriptions = descriptions;

View on GitHub (pinned to e1c734241f)

Solutions

  1. Check the byte[] passed to template() is non-null and non-empty before calling it; log it if unsure
  2. Verify the template resource exists on the deployment module classpath and the path is correct
  3. If you don't need a custom template, omit template() and let build() use DEFAULT_TEMPLATE

Example fix

// before
byte[] tpl = loadResourceOrNull("my-page.html");
DevUIContent.builder().fileName("my-page.html").template(tpl).build();
// after
byte[] tpl = loadResourceOrNull("my-page.html");
if (tpl == null || tpl.length == 0) {
    throw new IllegalStateException("Template resource my-page.html missing on classpath");
}
DevUIContent.builder().fileName("my-page.html").template(tpl).build();
Defensive patterns

Strategy: validation

Validate before calling

if (templateBytes == null || templateBytes.length == 0) {
    throw new IllegalArgumentException("DevUI template bytes must be non-null and non-empty");
}

Type guard

boolean isValidTemplate(byte[] t) { return t != null && t.length > 0; }

Try / catch

try {
    builder.template(bytes);
} catch (RuntimeException e) {
    if ("Invalid template".equals(e.getMessage())) { /* fall back to default template */ }
    else throw e;
}

Prevention

When it happens

Trigger: Calling DevUIContent.builder().template(null) or template(new byte[0]) — typically when the resource loaded into a byte[] was missing, so the variable passed was null.

Common situations: A classpath resource was read with IO.classPaths... or InputStream that returned null because the HTML/JS file path was misspelled or the file was not included in the deployment module.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/6b6c3b2fb1785fa3. Report an issue: GitHub.