bazelbuild/bazel · error · IllegalArgumentException

Method %s#getAssociatedTypeConstructor has an invalid signat

Error message

Method %s#getAssociatedTypeConstructor has an invalid signature; expected 'public static TypeConstructor getAssociatedTypeConstructor()'

What it means

After finding a unique getAssociatedTypeConstructor method, CallUtils validates it is exactly 'public static TypeConstructor getAssociatedTypeConstructor()' — public, static, no parameters, return type exactly TypeConstructor. Any deviation (private, non-static, parameters, or a subtype/boxed return) throws this IllegalArgumentException naming the class.

Source

Thrown at src/main/java/net/starlark/java/eval/CallUtils.java:471

        if (found != null) {
          throw new IllegalArgumentException(
              String.format(
                  "Class %s has multiple methods named getAssociatedTypeConstructor",
                  clazz.getName()));
        }
        found = m;
      }
    }
    if (found == null) {
      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. Declare exactly: public static TypeConstructor getAssociatedTypeConstructor() { return ...; }.
  2. Return the exact TypeConstructor type (assign the subtype to a TypeConstructor variable if needed).
  3. Remove any parameters; obtain context from static configuration instead.

Example fix

// before
public static MyTypeConstructor getAssociatedTypeConstructor(Flag f) {...}

// after
public static TypeConstructor getAssociatedTypeConstructor() {...}
Defensive patterns

Strategy: validation

Validate before calling

// Validate the accessor shape reflectively
static void checkAccessorSignature(Class<?> c) {
  for (Method m : c.getDeclaredMethods()) {
    if (!m.getName().equals("getAssociatedTypeConstructor")) continue;
    if (!Modifier.isPublic(m.getModifiers()) || !Modifier.isStatic(m.getModifiers())
        || m.getParameterCount() != 0
        || !m.getReturnType().equals(TypeConstructor.class)) {
      throw new IllegalArgumentException("bad signature: " + m);
    }
  }
}

Prevention

When it happens

Trigger: Declaring the method as an instance method; adding a parameter; returning a TypeConstructor subclass or void; marking it protected/package-private.

Common situations: Following an interface that prescribes an instance-style getter instead of the static convention; refactor changing return type to a more specific constructor class; access reduced during API cleanup.

Related errors


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