spring-projects/spring-boot · error · IllegalArgumentException
InputStream must not be null.
Error message
InputStream must not be null.
What it means
ConfigurationMetadataRepositoryJsonBuilder.withJsonResource rejects a null InputStream immediately with IllegalArgumentException. The builder cannot read metadata from nothing, so it fails fast rather than produce an empty repository.
Source
Thrown at configuration-metadata/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/ConfigurationMetadataRepositoryJsonBuilder.java:75
return withJsonResource(inputStream, this.defaultCharset);
}
/**
* Add the content of a {@link ConfigurationMetadataRepository} defined by the
* specified {@link InputStream} JSON document using the specified {@link Charset}. If
* this metadata repository holds items that were loaded previously, these are
* ignored.
* <p>
* Leaves the stream open when done.
* @param inputStream the source input stream
* @param charset the charset of the input
* @return this builder
* @throws IOException in case of I/O errors
*/
public ConfigurationMetadataRepositoryJsonBuilder withJsonResource(InputStream inputStream, Charset charset)
throws IOException {
if (inputStream == null) {
throw new IllegalArgumentException("InputStream must not be null.");
}
this.repositories.add(add(inputStream, charset));
return this;
}
/**
* Build a {@link ConfigurationMetadataRepository} with the current state of this
* builder.
* @return this builder
*/
public ConfigurationMetadataRepository build() {
SimpleConfigurationMetadataRepository result = new SimpleConfigurationMetadataRepository();
for (SimpleConfigurationMetadataRepository repository : this.repositories) {
result.include(repository);
}
return result;
}
View on GitHub (pinned to 5b2dbdbb8b)
Solutions
- Null-check the stream before calling withJsonResource; skip if absent when an empty contribution is acceptable.
- Fix the resource path/entry name so getResourceAsStream or getJarEntry returns a real stream.
- If null should be a no-op, wrap: if (in != null) builder.withJsonResource(in);
Example fix
// before
builder.withJsonResource(getClass().getResourceAsStream("META-INF/spring-configuration-metadata.json"));
// after
InputStream in = getClass().getResourceAsStream("META-INF/spring-configuration-metadata.json");
if (in != null) {
builder.withJsonResource(in);
} Defensive patterns
Strategy: validation
Validate before calling
if (inputStream == null) {
throw new IllegalArgumentException("inputStream is null; resource may not exist.");
}
builder.withJsonResource(inputStream); Type guard
// Ensure non-null before invoking the builder Objects.requireNonNull(inputStream, "metadata stream");
Try / catch
try { builder.withJsonResource(in).build(); }
catch (IllegalArgumentException ex) {
if ("InputStream must not be null.".equals(ex.getMessage())) {
// resolve the resource correctly and retry with a real stream
} else throw ex;
} Prevention
- Treat getResourceAsStream results as @Nullable; null-check before use.
- When loading from jars, only call withJsonResource when getJarEntry returns non-null (as ChangelogGenerator does).
- Add a unit test that feeds a known-good metadata stream to catch regressions.
When it happens
Trigger: Calling builder.withJsonResource(null) directly, or via create(InputStream...) with a null element in the varargs array. ChangelogGenerator.buildRepository guards against a missing jar entry (only calls withJsonResource when metadataEntry != null), so this typically arises from user code that resolves a resource/stream that came back null.
Common situations: Loading metadata from a classpath resource via getResourceAsStream where the resource name is wrong (returns null); a JarEntry lookup that returned null being passed anyway; wrapping an optional stream without a null check.
Related errors
- 'files' must not be null
- Invalid layers.xml configuration
- Multiple '{}' nodes found
- Failed to read configuration metadata
- Invalid value for option '--environment'. Expected 'NAME=VAL
AI-assisted analysis of spring-projects/spring-boot@5b2dbdbb8b (2026-08-04).
Data as JSON: /data/errors/132dd1216a114ba7.json.
Report an issue: GitHub.