{"id":"132dd1216a114ba7","repo":"spring-projects/spring-boot","slug":"inputstream-must-not-be-null","errorCode":null,"errorMessage":"InputStream must not be null.","messagePattern":"InputStream must not be null\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"configuration-metadata/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/ConfigurationMetadataRepositoryJsonBuilder.java","lineNumber":75,"sourceCode":"\t\treturn withJsonResource(inputStream, this.defaultCharset);\n\t}\n\n\t/**\n\t * Add the content of a {@link ConfigurationMetadataRepository} defined by the\n\t * specified {@link InputStream} JSON document using the specified {@link Charset}. If\n\t * this metadata repository holds items that were loaded previously, these are\n\t * ignored.\n\t * <p>\n\t * Leaves the stream open when done.\n\t * @param inputStream the source input stream\n\t * @param charset the charset of the input\n\t * @return this builder\n\t * @throws IOException in case of I/O errors\n\t */\n\tpublic ConfigurationMetadataRepositoryJsonBuilder withJsonResource(InputStream inputStream, Charset charset)\n\t\t\tthrows IOException {\n\t\tif (inputStream == null) {\n\t\t\tthrow new IllegalArgumentException(\"InputStream must not be null.\");\n\t\t}\n\t\tthis.repositories.add(add(inputStream, charset));\n\t\treturn this;\n\t}\n\n\t/**\n\t * Build a {@link ConfigurationMetadataRepository} with the current state of this\n\t * builder.\n\t * @return this builder\n\t */\n\tpublic ConfigurationMetadataRepository build() {\n\t\tSimpleConfigurationMetadataRepository result = new SimpleConfigurationMetadataRepository();\n\t\tfor (SimpleConfigurationMetadataRepository repository : this.repositories) {\n\t\t\tresult.include(repository);\n\t\t}\n\t\treturn result;\n\t}\n","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/5b2dbdbb8be64415eb6552f81ff7c449c8d251e6/configuration-metadata/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/ConfigurationMetadataRepositoryJsonBuilder.java#L57-L93","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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);"],"exampleFix":"// before\nbuilder.withJsonResource(getClass().getResourceAsStream(\"META-INF/spring-configuration-metadata.json\"));\n// after\nInputStream in = getClass().getResourceAsStream(\"META-INF/spring-configuration-metadata.json\");\nif (in != null) {\n    builder.withJsonResource(in);\n}","handlingStrategy":"validation","validationCode":"if (inputStream == null) {\n    throw new IllegalArgumentException(\"inputStream is null; resource may not exist.\");\n}\nbuilder.withJsonResource(inputStream);","typeGuard":"// Ensure non-null before invoking the builder\nObjects.requireNonNull(inputStream, \"metadata stream\");","tryCatchPattern":"try { builder.withJsonResource(in).build(); }\ncatch (IllegalArgumentException ex) {\n    if (\"InputStream must not be null.\".equals(ex.getMessage())) {\n        // resolve the resource correctly and retry with a real stream\n    } else throw ex;\n}","preventionTips":["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."],"tags":["spring-boot","configuration-metadata","validation","null-check"],"analyzedSha":"5b2dbdbb8be64415eb6552f81ff7c449c8d251e6","analyzedAt":"2026-08-04T18:53:14.967Z","schemaVersion":2}