{"record":{"id":"c2c14e2f4c373195","repo":"bazelbuild/bazel","slug":"error-invoking-s-getassociatedtypeconstructor","errorCode":null,"errorMessage":"Error invoking %s#getAssociatedTypeConstructor","messagePattern":"Error invoking (.+?)#getAssociatedTypeConstructor","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/net/starlark/java/eval/CallUtils.java","lineNumber":481,"sourceCode":"      return null;\n    }\n\n    // Signature check.\n    if (!Modifier.isPublic(found.getModifiers())\n        || !Modifier.isStatic(found.getModifiers())\n        || !found.getReturnType().equals(TypeConstructor.class)\n        || found.getParameterCount() != 0) {\n      throw new IllegalArgumentException(\n          String.format(\n              \"Method %s#getAssociatedTypeConstructor has an invalid signature; \"\n                  + \"expected 'public static TypeConstructor getAssociatedTypeConstructor()'\",\n              clazz.getName()));\n    }\n\n    try {\n      return (TypeConstructor) found.invoke(null);\n    } catch (IllegalAccessException | InvocationTargetException | RuntimeException e) {\n      throw new IllegalArgumentException(\n          String.format(\"Error invoking %s#getAssociatedTypeConstructor\", clazz.getName()), e);\n    }\n  }\n}\n","sourceCodeStart":463,"sourceCodeEnd":486,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/net/starlark/java/eval/CallUtils.java#L463-L486","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\npublic static TypeConstructor getAssociatedTypeConstructor() {\n  return Registry.lookup(\"mytype\"); // throws if registry not yet populated\n}\n\n// after\nprivate static final TypeConstructor CTOR = TypeConstructor.of(\"mytype\");\npublic static TypeConstructor getAssociatedTypeConstructor() { return CTOR; }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  TypeConstructor tc = CallUtils.getAssociatedTypeConstructor(clazz);\n} catch (IllegalArgumentException e) {\n  Throwable root = e.getCause() != null ? e.getCause() : e;\n  throw new IllegalStateException(\"type constructor init failed for \" + clazz, root);\n}","preventionTips":["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."],"tags":["starlark","reflection","initialization","java"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}