junit-team/junit5 · error · JUnitException

AnnotationBasedArgumentsProvider does not override the provi

Error message

AnnotationBasedArgumentsProvider does not override the provideArguments(ParameterDeclarations, ExtensionContext, Annotation) method. Please report this issue to the maintainers of %s.

What it means

Thrown by the deprecated default provideArguments(ExtensionContext, A) in AnnotationBasedArgumentsProvider. It fires when a subclass neither overrides the current 3-arg provideArguments(ParameterDeclarations, ExtensionContext, A) nor the deprecated 2-arg variant. It signals a programming defect in a custom annotation-based arguments provider.

Source

Thrown at junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/AnnotationBasedArgumentsProvider.java:79

	public Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters, ExtensionContext context) {
		return annotations.stream().flatMap(annotation -> provideArguments(parameters, context, annotation));
	}

	/**
	 * Provide a {@link Stream} of {@link Arguments} &mdash; based on metadata in the
	 * provided annotation &mdash; to be passed to a {@code @ParameterizedTest} method.
	 *
	 * @param context the current extension context; never {@code null}
	 * @param annotation the annotation to process; never {@code null}
	 * @return a stream of arguments; never {@code null}
	 * @deprecated Please implement
	 * {@link #provideArguments(ParameterDeclarations, ExtensionContext, Annotation)}
	 * instead.
	 */
	@Deprecated(since = "5.13")
	@API(status = DEPRECATED, since = "5.13")
	protected Stream<? extends Arguments> provideArguments(ExtensionContext context, A annotation) {
		throw new JUnitException("""
				AnnotationBasedArgumentsProvider does not override the \
				provideArguments(ParameterDeclarations, ExtensionContext, Annotation) method. \
				Please report this issue to the maintainers of %s.""".formatted(getClass().getName()));
	}

	/**
	 * The returned {@code Stream} will be {@link Stream#close() properly closed}
	 * by the default implementation of
	 * {@link #provideArguments(ParameterDeclarations, ExtensionContext)},
	 * making it safe to use a resource such as
	 * {@link java.nio.file.Files#lines(java.nio.file.Path) Files.lines()}.
	 */
	protected Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters, ExtensionContext context,
			A annotation) {
		return provideArguments(context, annotation);
	}

}

View on GitHub (pinned to 956246301e)

Solutions

  1. Override `protected Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters, ExtensionContext context, MyAnno annotation)` in the subclass.
  2. If you cannot change the class, report the issue to the maintainers of that third-party provider as the message instructs.
  3. As a temporary stopgap, pin JUnit to a version whose ArgumentsProvider contract the provider implements.

Example fix

// before
class MyProvider extends AnnotationBasedArgumentsProvider<MyAnno> {
    // no overrides
}

// after
class MyProvider extends AnnotationBasedArgumentsProvider<MyAnno> {
    @Override
    protected Stream<? extends Arguments> provideArguments(
            ParameterDeclarations parameters, ExtensionContext context, MyAnno annotation) {
        return Stream.of(Arguments.of(annotation.value()));
    }
}
Defensive patterns

Strategy: validation

Validate before calling

// Fail fast at extension registration: assert the subclass overrides the 3-arg method.
Class<? extends AnnotationBasedArgumentsProvider<?>> provider = MyProvider.class;
boolean overrides3Arg = Arrays.stream(provider.getDeclaredMethods())
    .anyMatch(m -> m.getName().equals("provideArguments")
        && m.getParameterCount() == 3
        && !Modifier.isVolatile(m.getModifiers()));
if (!overrides3Arg) {
    throw new IllegalStateException(provider.getName()
        + " must override provideArguments(ParameterDeclarations, ExtensionContext, Annotation)");
}

Try / catch

try {
    // run the parameterized test that uses the custom provider
} catch (JUnitException e) {
    if (e.getMessage().contains("does not override the provideArguments")) {
        // implement the 3-arg override in the provider class named in the message
    } else throw e;
}

Prevention

When it happens

Trigger: A custom provider `class MyProvider extends AnnotationBasedArgumentsProvider<MyAnno>` registered via @ArgumentsSource, where the author forgot to override the 3-arg provideArguments. The framework's 3-arg default delegates to the 2-arg default, which throws.

Common situations: Upgrading JUnit from pre-5.13 (where the 2-arg was the contract) without adding the new override; following an outdated tutorial; abstract intermediate subclass left without implementation.

Related errors


AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04). Data as JSON: /data/errors/266d322db9945335.json. Report an issue: GitHub.