junit-team/junit5 · error · PreconditionViolationException

%s must not be null

Error message

%s must not be null

What it means

Thrown by the private checkNotNull in ResourceFilter when match(resource) is called with a null resource. Because ResourceFilter cannot use Preconditions (package cycle), it guards directly and raises PreconditionViolationException 'resource must not be null' before applying the predicate.

Source

Thrown at junit-platform-commons/src/main/java/org/junit/platform/commons/io/ResourceFilter.java:62

		this.predicate = predicate;
	}

	/**
	 * Test whether the given resource matches this filter.
	 *
	 * @param resource the resource to test; never {@code null}
	 * @return {@code true} if the resource matches this filter, otherwise
	 * {@code false}
	 */
	public boolean match(Resource resource) {
		return predicate.test(checkNotNull(resource, "resource"));
	}

	// Cannot use Preconditions due to package cycle
	@Contract("null, _ -> fail; !null, _ -> param1")
	private static <T> T checkNotNull(@Nullable T input, String title) {
		if (input == null) {
			throw new PreconditionViolationException(title + " must not be null");
		}
		return input;
	}

}

View on GitHub (pinned to f070c699a0)

Solutions

  1. Filter out null resources before calling match(): stream.filter(Objects::nonNull).
  2. Ensure the resource source never yields null.
  3. Null-check the resource before invoking match() and handle the missing case explicitly.

Example fix

// before
boolean ok = filter.match(maybeNullResource);

// after
boolean ok = maybeNullResource != null && filter.match(maybeNullResource);
Defensive patterns

Strategy: type-guard

Validate before calling

// Filter nulls before applying the ResourceFilter
Stream<Resource> safe = resources.filter(Objects::nonNull);
safe.forEach(r -> filter.match(r));

Type guard

static boolean isNonNullOrginal(Resource r) { return r != null; }

Prevention

When it happens

Trigger: Calling resourceFilter.match(null). The checkNotNull(resource, "resource") guard fires before predicate.test.

Common situations: Filtering a stream of resources where some elements are null. Passing a resource reference that was not resolved (e.g. lookup returned null) into the filter.

Related errors


AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11). Data as JSON: /api/errors/93d19520abb6953f. Report an issue: GitHub.