{"record":{"id":"3206cad552cc0f94","repo":"bazelbuild/bazel","slug":"class-s-has-multiple-methods-named-getassociatedt","errorCode":null,"errorMessage":"Class %s has multiple methods named getAssociatedTypeConstructor","messagePattern":"Class (.+?) has multiple methods named getAssociatedTypeConstructor","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/net/starlark/java/eval/CallUtils.java","lineNumber":454,"sourceCode":"   * getAssociatedTypeConstructor()} static method, or null if it does not have such a method.\n   *\n   * @throws IllegalArgumentException if the method exists but has an unexpected signature, or if it\n   *     does not evaluate successfully\n   */\n  @Nullable\n  private static TypeConstructor getAssociatedTypeConstructor(Class<?> clazz) {\n    // Special-case bool, which is represented by Java booleans and does not have its own class.\n    // (String.class does not need special-casing because it's already been replaced by\n    // StringModule.class by this point.)\n    if (clazz.equals(Boolean.class) || clazz.equals(boolean.class)) {\n      return Types.BOOL_CONSTRUCTOR;\n    }\n\n    Method found = null;\n    for (Method m : clazz.getDeclaredMethods()) {\n      if (m.getName().equals(\"getAssociatedTypeConstructor\")) {\n        if (found != null) {\n          throw new IllegalArgumentException(\n              String.format(\n                  \"Class %s has multiple methods named getAssociatedTypeConstructor\",\n                  clazz.getName()));\n        }\n        found = m;\n      }\n    }\n    if (found == null) {\n      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(","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/net/starlark/java/eval/CallUtils.java#L436-L472","documentation":"CallUtils.getAssociatedTypeConstructor scans a class's declared methods for 'getAssociatedTypeConstructor' to find its fixed Starlark type constructor. If more than one declared method carries that name (regardless of signature), the lookup is ambiguous and this IllegalArgumentException is thrown.","triggerScenarios":"Declaring both `static TypeConstructor getAssociatedTypeConstructor()` and an overloaded `getAssociatedTypeConstructor(Object o)` on the same class; keeping a private helper with the same name as the public accessor.","commonSituations":"Copy-pasting the accessor pattern and leaving the original; refactoring that introduces an overload; multiple people adding the hook in a merge.","solutions":["Keep a single declared method named getAssociatedTypeConstructor.","Rename helper/overload variants to different names.","Delete dead private variants left by refactors."],"exampleFix":"// before\nclass T {\n  public static TypeConstructor getAssociatedTypeConstructor() {...}\n  private static TypeConstructor getAssociatedTypeConstructor(boolean legacy) {...}\n}\n\n// after\nclass T {\n  public static TypeConstructor getAssociatedTypeConstructor() {...}\n  private static TypeConstructor legacyTypeConstructor(boolean legacy) {...}\n}","handlingStrategy":"validation","validationCode":"// Assert a single declared accessor before registration\nstatic void checkSingleAccessor(Class<?> c) {\n  int n = 0;\n  for (Method m : c.getDeclaredMethods()) if (m.getName().equals(\"getAssociatedTypeConstructor\")) n++;\n  if (n > 1) throw new IllegalArgumentException(c + \" declares \" + n + \" accessors\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reserve the exact name getAssociatedTypeConstructor for the accessor only.","Name helpers differently during refactors.","Review merges for duplicated accessor methods."],"tags":["starlark","reflection","type-system","java"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}