bazelbuild/bazel · error · IllegalArgumentException
Error invoking %s#getAssociatedTypeConstructor
Error message
Error invoking %s#getAssociatedTypeConstructor
What it means
The signature check passed, but invoking getAssociatedTypeConstructor via reflection failed: IllegalAccessException (access blocked despite being public, e.g. module boundaries), InvocationTargetException (the method body threw), or the body threw a RuntimeException directly (e.g. NPE while initializing a static type constructor). The original exception is chained as the cause.
Source
Thrown at src/main/java/net/starlark/java/eval/CallUtils.java:481
return null;
}
// Signature check.
if (!Modifier.isPublic(found.getModifiers())
|| !Modifier.isStatic(found.getModifiers())
|| !found.getReturnType().equals(TypeConstructor.class)
|| found.getParameterCount() != 0) {
throw new IllegalArgumentException(
String.format(
"Method %s#getAssociatedTypeConstructor has an invalid signature; "
+ "expected 'public static TypeConstructor getAssociatedTypeConstructor()'",
clazz.getName()));
}
try {
return (TypeConstructor) found.invoke(null);
} catch (IllegalAccessException | InvocationTargetException | RuntimeException e) {
throw new IllegalArgumentException(
String.format("Error invoking %s#getAssociatedTypeConstructor", clazz.getName()), e);
}
}
}
View on GitHub (pinned to e6e199d060)
Solutions
- Inspect the chained cause to find the real failure inside the method body and fix it.
- Make the static accessor defensive: build the TypeConstructor lazily or from fully-initialized constants.
- On JDK 9+, ensure the package is exported/opened to the reflecting module.
- Avoid circular static initialization between the class and its type constructor.
Example fix
// before
public static TypeConstructor getAssociatedTypeConstructor() {
return Registry.lookup("mytype"); // throws if registry not yet populated
}
// after
private static final TypeConstructor CTOR = TypeConstructor.of("mytype");
public static TypeConstructor getAssociatedTypeConstructor() { return CTOR; } Defensive patterns
Strategy: try-catch
Try / catch
try {
TypeConstructor tc = CallUtils.getAssociatedTypeConstructor(clazz);
} catch (IllegalArgumentException e) {
Throwable root = e.getCause() != null ? e.getCause() : e;
throw new IllegalStateException("type constructor init failed for " + clazz, root);
} Prevention
- Initialize type constructors from constants, not registries populated later.
- Avoid circular static initialization between a class and its type constructor.
- On JDK 9+, open/export the declaring package to reflective callers.
When it happens
Trigger: The static method body throws (null type registry, circular static init, missing dependency); JPMS denies access to the declaring class; static initializer order causes the constructor to depend on not-yet-initialized state.
Common situations: Type constructor built from a registry that is only populated later; module-info or --add-exports missing in JDK 9+ environments; exception thrown during class initialization surfacing as ExceptionInInitializerError wrapped here.
Related errors
- Class %s has multiple methods named getAssociatedTypeConstru
- Method %s#getAssociatedTypeConstructor has an invalid signat
- No member %s of the %s annotation found for element.
- Expected one of %s and %s to be a subclass of the other
- Class %s has an incompatible overload of annotated method %s
AI-assisted analysis of bazelbuild/bazel@e6e199d060 (2026-08-14).
Data as JSON: /api/errors/c2c14e2f4c373195.
Report an issue: GitHub.