{"record":{"id":"25a6eded6bbd3077","repo":"bazelbuild/bazel","slug":"failed-to-create-converter","errorCode":null,"errorMessage":"Failed to create converter","messagePattern":"Failed to create converter","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"src/main/java/com/google/devtools/common/options/testing/ConverterTester.java","lineNumber":51,"sourceCode":"  private final Converter<?> converter;\n  private final Class<? extends Converter<?>> converterClass;\n  private final Object conversionContext;\n  private final EqualsTester tester = new EqualsTester();\n  private final LinkedHashSet<String> testedInputs = new LinkedHashSet<>();\n  private final ArrayList<ImmutableList<String>> inputLists = new ArrayList<>();\n\n  /** Creates a new ConverterTester which will test the given Converter class. */\n  public ConverterTester(Class<? extends Converter<?>> converterClass, Object conversionContext) {\n    this.converterClass = converterClass;\n    this.converter = createConverter();\n    this.conversionContext = conversionContext;\n  }\n\n  private Converter<?> createConverter() {\n    try {\n      return converterClass.getDeclaredConstructor().newInstance();\n    } catch (ReflectiveOperationException ex) {\n      throw new AssertionError(\"Failed to create converter\", ex);\n    }\n  }\n\n  /** Returns the class this ConverterTester is testing. */\n  public Class<? extends Converter<?>> getConverterClass() {\n    return converterClass;\n  }\n\n  /**\n   * Returns whether this ConverterTester has a test for the given input, i.e., addEqualityGroup\n   * was called with the given string.\n   */\n  public boolean hasTestForInput(String input) {\n    return testedInputs.contains(input);\n  }\n\n  /**\n   * Adds a set of valid inputs which are expected to convert to equal values.","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/com/google/devtools/common/options/testing/ConverterTester.java#L33-L69","documentation":"ConverterTester reflectively instantiates the Converter under test via getDeclaredConstructor().newInstance(); if that throws any ReflectiveOperationException it is wrapped in this AssertionError. In practice the converter class has no accessible no-arg constructor, or is abstract/interface/non-public, so the test harness cannot create an instance.","triggerScenarios":"ConverterTester constructed with a Converter class that lacks a public no-arg constructor; converter declared abstract or as an interface; constructor package-private and the test runs in a different package; constructor exists but throws (newInstance wraps constructor exceptions in InvocationTargetException, a ReflectiveOperationException).","commonSituations":"Writing a new converter that takes constructor arguments or uses a private ctor with a static factory; converting an existing converter to a non-static inner class (implicit outer-class ctor parameter); JDK 9+ module access restrictions hiding the ctor.","solutions":["Add a public no-argument constructor to the converter class.","Make the class concrete (not abstract/interface) and top-level or static-nested.","Ensure the class is public and visible to the test.","Ensure the no-arg constructor does not itself throw."],"exampleFix":"// before\nclass MyConverter implements Converter<String> {\n  private MyConverter(Config cfg) { ... }\n}\n\n// after\nclass MyConverter implements Converter<String> {\n  public MyConverter() { this(DEFAULT_CONFIG); }\n  private MyConverter(Config cfg) { ... }\n}","handlingStrategy":"validation","validationCode":"// Fail fast with a clear message before constructing the tester\nstatic Class<? extends Converter<?>> checkInstantiable(Class<? extends Converter<?>> c) {\n  int mods = c.getModifiers();\n  if (Modifier.isAbstract(mods) || c.isInterface()) throw new IllegalArgumentException(c + \" must be concrete\");\n  try { c.getDeclaredConstructor(); } catch (NoSuchMethodException e) {\n    throw new IllegalArgumentException(c + \" needs a public no-arg constructor\", e);\n  }\n  return c;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always give Converter implementations an explicit public no-arg constructor.","Prefer stateless converters so reflective instantiation is trivial.","Add a compile-time-only unit test that reflectively checks the ctor for every converter."],"tags":["testing","reflection","options","converter"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}