quarkusio/quarkus · error · IllegalStateException

Global variable field declared on " + field.declaringClass()

Error message

Global variable field declared on " + field.declaringClass().name() + "  must be static: " + field

What it means

IllegalStateException from TemplateGlobalGenerator.validate(FieldInfo): a field annotated @TemplateGlobal is not static. Global variables exposed as fields must be static so their value can be read without an instance; the declaring class and field are included in the message.

Source

Thrown at independent-projects/qute/generator/src/main/java/io/quarkus/qute/generator/TemplateGlobalGenerator.java:183

                            + method);
        }
        if (method.returnType().kind() == Kind.VOID) {
            throw new IllegalStateException("Global variable method declared on " + method.declaringClass().name()
                    + " must not return void: " + method);
        }
        if (!method.parameterTypes().isEmpty()) {
            throw new IllegalStateException("Global variable method declared on " + method.declaringClass().name()
                    + " must not accept any parameter: " + method);
        }
        if (Modifier.isPrivate(method.flags())) {
            throw new IllegalStateException("Global variable method declared on " + method.declaringClass().name()
                    + " must not be private: " + method);
        }
    }

    public static void validate(FieldInfo field) {
        if (!Modifier.isStatic(field.flags())) {
            throw new IllegalStateException(
                    "Global variable field declared on " + field.declaringClass().name() + "  must be static: " + field);
        }
        if (Modifier.isPrivate(field.flags())) {
            throw new IllegalStateException("Global variable field declared on " + field.declaringClass().name()
                    + " must not be private: " + field);
        }
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Make the @TemplateGlobal field static
  2. Or expose the value through a static @TemplateGlobal method instead
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at independent-projects/qute/generator/src/main/java/io/quarkus/qute/generator/TemplateGlobalGenerator.java:183 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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