google/guava · error · ParameterNotInstantiableException
Cannot determine value for parameter %s of %s
Error message
Cannot determine value for parameter %s of %s
What it means
Thrown as ParameterNotInstantiableException by generateDummyArg() when, for a non-@Nullable constructor/factory parameter, FreshValueGenerator.generateFresh() returns null (no sample/default is registered for that parameter's type). The tester cannot even invoke the factory to begin testing, so it aborts that factory.
Source
Thrown at android/guava-testlib/src/com/google/common/testing/ClassSanityTester.java:687
@Override
@Nullable Object interfaceMethodCalled(Class<?> interfaceType, Method method) {
return getDummyValue(TypeToken.of(interfaceType).method(method).getReturnType());
}
};
for (Entry<Class<?>, Collection<Object>> entry : distinctValues.asMap().entrySet()) {
generator.addSampleInstances((Class) entry.getKey(), entry.getValue());
}
return generator;
}
private static @Nullable Object generateDummyArg(Parameter param, FreshValueGenerator generator)
throws ParameterNotInstantiableException {
if (isNullable(param)) {
return null;
}
Object arg = generator.generateFresh(param.getType());
if (arg == null) {
throw new ParameterNotInstantiableException(param);
}
return arg;
}
private static <X extends Throwable> void throwFirst(List<X> exceptions) throws X {
if (!exceptions.isEmpty()) {
throw exceptions.get(0);
}
}
/** Factories with the least number of parameters are listed first. */
private static <T> ImmutableList<Invokable<?, ? extends T>> getFactories(TypeToken<T> type) {
List<Invokable<?, ? extends T>> factories = new ArrayList<>();
for (Method method : type.getRawType().getDeclaredMethods()) {
Invokable<?, ?> invokable = type.method(method);
if (!invokable.isPrivate()
&& !invokable.isSynthetic()
&& invokable.isStatic()View on GitHub (pinned to 94f39958ba)
Solutions
- Register a default instance for the parameter type via ClassSanityTester.setDefault(Class, instance).
- Mark the parameter @Nullable if null is a valid argument so the tester passes null instead of failing.
- Provide a FreshValueGenerator sample or restrict the tested factories.
Example fix
// before sanityTester.testNulls(MyService.class); // ctor takes Executor -> no default // after sanityTester.setDefault(Executor.class, Runnable::run); sanityTester.testNulls(MyService.class);
Defensive patterns
Strategy: validation
Validate before calling
sanityTester.setDefault(Executor.class, Runnable::run); // register default sanityTester.testNulls(MyService.class);
Try / catch
try { sanityTester.testNulls(MyType.class); }
catch (ClassSanityTester.ParameterNotInstantiableException e) {
// e.getMessage() names the parameter; register a default or mark @Nullable, retry
} Prevention
- Register setDefault(Class, instance) for every non-primitive, non-@Nullable factory parameter type.
- Annotate genuinely nullable parameters with @Nullable.
When it happens
Trigger: Calling ClassSanityTester.test*(...) on a class whose constructor or static factory has a parameter of a type with no known default (interface/abstract/third-party type) and not marked @Nullable. generateFresh returns null -> throw ParameterNotInstantiableException.
Common situations: Testing a value object that takes a collaborator interface in its constructor; types not covered by the built-in default value table; newly added factory parameters of exotic types.
Related errors
- Null check failed on return value of %s
- Serialization failed on return value of %s
- Cannot generate distinct value for parameter %s of %s
- unable to extract method from test: not a TestCase.
- Error extracting features from tester annotation.
AI-assisted analysis of google/guava@94f39958ba (2026-08-13).
Data as JSON: /api/errors/5d01ab86da193bb3.
Report an issue: GitHub.