{"record":{"id":"902547b178e027db","repo":"bazelbuild/bazel","slug":"s-missing-getstarlarktype-starlarksemantics-meth","errorCode":null,"errorMessage":"%s missing getStarlarkType(StarlarkSemantics) method","messagePattern":"(.+?) missing getStarlarkType\\(StarlarkSemantics\\) method","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/main/java/net/starlark/java/eval/CallUtils.java","lineNumber":412,"sourceCode":"\n  /**\n   * Returns true if a {@link StarlarkBuiltinAutoType} should be generated for the given class. This\n   * is the case if the class is annotated as {@link StarlarkBuiltin}, and does not override {@link\n   * StarlarkValue#getStarlarkType}.\n   */\n  private static boolean wantStarlarkBuiltinAutoType(Class<?> clazz) {\n    if (StarlarkAnnotations.getStarlarkBuiltin(clazz) == null) {\n      return false;\n    }\n    Method getter;\n    try {\n      // LINT.IfChange\n      getter = clazz.getMethod(\"getStarlarkType\", StarlarkSemantics.class);\n      // LINT.ThenChange(//src/main/java/net/starlark/java/eval/StarlarkValue.java)\n    } catch (NoSuchMethodException e) {\n      // All StarlarkBuiltin-annotated classes must implement StarlarkValue and thus have a\n      // getStarlarkType method.\n      throw new IllegalStateException(\n          String.format(\"%s missing getStarlarkType(StarlarkSemantics) method\", clazz), e);\n    }\n    return getter.getDeclaringClass().equals(StarlarkValue.class);\n  }\n\n  /**\n   * Certain Java classes/interfaces should be associated with a special fixed {@link StarlarkType}\n   * instead of a generated {@link StarlarkBuiltinAutoType}. Returns that fixed {@link\n   * StarlarkType}, or null otherwise.\n   */\n  @Nullable\n  private static StarlarkType getFixedStarlarkType(Class<?> clazz) {\n    @Nullable StarlarkBuiltin annotation = StarlarkAnnotations.getStarlarkBuiltin(clazz);\n    if (annotation != null && annotation.isStructType()) {\n      // Interpret com.google.devtools.build.lib.starlarkbuildapi.core.StructApi as a marker for\n      // an arbitrary struct type.\n      return Types.ANY_STRUCT;\n    }","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/net/starlark/java/eval/CallUtils.java#L394-L430","documentation":"Every class annotated with @StarlarkBuiltin must implement StarlarkValue, which declares getStarlarkType(StarlarkSemantics). When CallUtils enables builtin auto-typing it reflectively looks up that method via clazz.getMethod(\"getStarlarkType\", StarlarkSemantics.class); NoSuchMethodException is rethrown as this IllegalStateException naming the offending class.","triggerScenarios":"Adding @StarlarkBuiltin to a class that does not implement StarlarkValue (directly or via an interface); implementing StarlarkValue from an older version whose getStarlarkType signature differs (parameter type changed to StarlarkSemantics in a newer release); mixing starlark jar versions so the interface in the class's hierarchy lacks the method.","commonSituations":"Upgrading the Starlark library where the StarlarkValue interface gained/changed getStarlarkType; annotating a plain data class to expose it to Starlark without implementing the value interface; duplicate starlark artifacts on the classpath with different interface definitions (guarded by the LINT.IfChange marker linking this code to StarlarkValue.java).","solutions":["Make the @StarlarkBuiltin-annotated class implement StarlarkValue (it then inherits or implements getStarlarkType(StarlarkSemantics)).","If you implement it manually, match the exact signature: public StarlarkType getStarlarkType(StarlarkSemantics semantics).","Align all starlark artifacts to one version so the interface definition is unique.","Clean rebuild after upgrading the Starlark library."],"exampleFix":"// before\n@StarlarkBuiltin(name = \"widget\")\nclass Widget { ... } // not a StarlarkValue\n\n// after\n@StarlarkBuiltin(name = \"widget\")\nclass Widget implements StarlarkValue { ... }","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean isValidBuiltinClass(Class<?> c) {\n  return c.isAnnotationPresent(StarlarkBuiltin.class)\n      && StarlarkValue.class.isAssignableFrom(c);\n}","tryCatchPattern":null,"preventionTips":["Always pair @StarlarkBuiltin with 'implements StarlarkValue'.","Keep a single Starlark version on the classpath.","Add a test that reflects over StarlarkValue to confirm the getStarlarkType(StarlarkSemantics) signature exists."],"tags":["starlark","annotations","type-system","versioning"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}