quarkusio/quarkus · error
Template extension method declared on must not be private:
Error message
Template extension method declared on must not be private:
What it means
Template extension methods are invoked statically from generated code without an instance of the declaring class. Qute rejects any @TemplateExtension method that is private because it cannot be invoked from the generated resolver class.
Source
Thrown at independent-projects/qute/generator/src/main/java/io/quarkus/qute/generator/ExtensionMethodGenerator.java:89
public static final String PRIORITY = "priority";
public static final String NAMESPACE = "namespace";
public static final String PATTERN = "pattern";
public ExtensionMethodGenerator(IndexView index, ClassOutput classOutput) {
super(index, classOutput);
}
public static void validate(MethodInfo method, String namespace) {
if (!Modifier.isStatic(method.flags())) {
throw new IllegalStateException(
"Template extension method declared on " + method.declaringClass().name() + " must be static: " + method);
}
if (method.returnType().kind() == Kind.VOID) {
throw new IllegalStateException("Template extension method declared on " + method.declaringClass().name()
+ " must not return void: " + method);
}
if (Modifier.isPrivate(method.flags())) {
throw new IllegalStateException("Template extension method declared on " + method.declaringClass().name()
+ " must not be private: " + method);
}
}
/**
*
* @param method
* @param matchName
* @param matchNames
* @param matchRegex
* @param priority
* @return the fully qualified name of the generated class
*/
public String generate(MethodInfo method, String matchName, List<String> matchNames, String matchRegex, Integer priority) {
LOG.debugf("Generating resolver for extension method declared on %s: %s", method.declaringClass(), method);
AnnotationInstance extensionAnnotation = method.annotation(TEMPLATE_EXTENSION);View on GitHub (pinned to e1c734241f)
Solutions
- Make the method at least package-private or public (keep it static)
- Remove the @TemplateExtension annotation if the method should not be exposed to templates
- Move the method to a dedicated extension class with appropriate visibility
Example fix
// before
@TemplateExtension
private static String slugify(String val) { ... }
// after
@TemplateExtension
static String slugify(String val) { ... } Defensive patterns
Strategy: validation
Validate before calling
if (java.lang.reflect.Modifier.isPrivate(m.getModifiers()))
throw new IllegalStateException("@TemplateExtension method must not be private: " + m); Prevention
- Keep extension methods package-private or public
- Avoid narrowing visibility of annotated methods during refactoring
- Grep for @TemplateExtension on private methods in CI
When it happens
Trigger: Annotating a private static method with @TemplateExtension, or making a previously package-private/public extension method private; detected by ExtensionMethodGenerator.validate during build.
Common situations: Narrowing visibility during refactoring; helper methods annotated by mistake; extension methods defined inside another class as private helpers.
Related errors
- Template extension method declared on must be static:
- Template extension method declared on must not return void:
- A template extension method matching multiple names or a reg
- Template extension method declared on must accept at least
- Template extension method declared on must accept at least
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/45fa43a4936e0877.
Report an issue: GitHub.