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

  1. Inspect the chained cause to find the real failure inside the method body and fix it.
  2. Make the static accessor defensive: build the TypeConstructor lazily or from fully-initialized constants.
  3. On JDK 9+, ensure the package is exported/opened to the reflecting module.
  4. 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

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


AI-assisted analysis of bazelbuild/bazel@e6e199d060 (2026-08-14). Data as JSON: /api/errors/c2c14e2f4c373195. Report an issue: GitHub.