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 DefaultResource when a null value is supplied to a constructor/state field that must be non-null. DefaultResource cannot use Preconditions (package cycle), so it performs its own null check and raises PreconditionViolationException '<title> must not be null'. The guard is a generic @Contract-annotated helper used for name/uri inputs.

Source

Thrown at junit-platform-commons/src/main/java/org/junit/platform/commons/io/DefaultResource.java:63

			return true;
		}
		if (obj instanceof org.junit.platform.commons.io.Resource that) {
			return this.name.equals(that.getName()) //
					&& this.uri.equals(that.getUri());
		}
		return false;
	}

	@Override
	public int hashCode() {
		return Objects.hash(name, uri);
	}

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

}

View on GitHub (pinned to f070c699a0)

Solutions

  1. Pass non-null name and uri when constructing a DefaultResource.
  2. Null-check inputs before creating the resource and reject with a clearer message.
  3. Use a higher-level resource factory rather than constructing DefaultResource directly.

Example fix

// before
Resource r = new DefaultResource(null, someUri);

// after
Resource r = new DefaultResource(Objects.requireNonNull(name, "name"), Objects.requireNonNull(uri, "uri"));
Defensive patterns

Strategy: validation

Validate before calling

// Null-check name/uri before constructing DefaultResource
String name = Objects.requireNonNull(resource.getName(), "name");
URI uri = Objects.requireNonNull(resource.getUri(), "uri");
new DefaultResource(name, uri);

Prevention

When it happens

Trigger: Constructing or invoking a DefaultResource method with a null name or uri argument. The checkNotNull guard fires on the offending argument.

Common situations: Custom code in the platform-commons-io area creating DefaultResource with null inputs. Resource lookup returning null name/uri being passed through. Internal misuse of the resource abstraction.

Related errors


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