bazelbuild/bazel · error · AssertionError
Failed to create converter
Error message
Failed to create converter
What it means
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.
Source
Thrown at src/main/java/com/google/devtools/common/options/testing/ConverterTester.java:51
private final Converter<?> converter;
private final Class<? extends Converter<?>> converterClass;
private final Object conversionContext;
private final EqualsTester tester = new EqualsTester();
private final LinkedHashSet<String> testedInputs = new LinkedHashSet<>();
private final ArrayList<ImmutableList<String>> inputLists = new ArrayList<>();
/** Creates a new ConverterTester which will test the given Converter class. */
public ConverterTester(Class<? extends Converter<?>> converterClass, Object conversionContext) {
this.converterClass = converterClass;
this.converter = createConverter();
this.conversionContext = conversionContext;
}
private Converter<?> createConverter() {
try {
return converterClass.getDeclaredConstructor().newInstance();
} catch (ReflectiveOperationException ex) {
throw new AssertionError("Failed to create converter", ex);
}
}
/** Returns the class this ConverterTester is testing. */
public Class<? extends Converter<?>> getConverterClass() {
return converterClass;
}
/**
* Returns whether this ConverterTester has a test for the given input, i.e., addEqualityGroup
* was called with the given string.
*/
public boolean hasTestForInput(String input) {
return testedInputs.contains(input);
}
/**
* Adds a set of valid inputs which are expected to convert to equal values.View on GitHub (pinned to e6e199d060)
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.
Example fix
// before
class MyConverter implements Converter<String> {
private MyConverter(Config cfg) { ... }
}
// after
class MyConverter implements Converter<String> {
public MyConverter() { this(DEFAULT_CONFIG); }
private MyConverter(Config cfg) { ... }
} Defensive patterns
Strategy: validation
Validate before calling
// Fail fast with a clear message before constructing the tester
static Class<? extends Converter<?>> checkInstantiable(Class<? extends Converter<?>> c) {
int mods = c.getModifiers();
if (Modifier.isAbstract(mods) || c.isInterface()) throw new IllegalArgumentException(c + " must be concrete");
try { c.getDeclaredConstructor(); } catch (NoSuchMethodException e) {
throw new IllegalArgumentException(c + " needs a public no-arg constructor", e);
}
return c;
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Failed to parse input: "%s"
- '" + input + "' is not a boolean
- '" + input + "' is not an int
- '" + input + "' is not a long
- '" + input + "' is not a double
AI-assisted analysis of bazelbuild/bazel@e6e199d060 (2026-08-14).
Data as JSON: /api/errors/25a6eded6bbd3077.
Report an issue: GitHub.