{"id":"93d716537065e3c2","repo":"spring-projects/spring-boot","slug":"failed-to-read-configuration-metadata","errorCode":null,"errorMessage":"Failed to read configuration metadata","messagePattern":"Failed to read configuration metadata","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"configuration-metadata/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/ConfigurationMetadataRepositoryJsonBuilder.java","lineNumber":103,"sourceCode":"\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\n\tprivate SimpleConfigurationMetadataRepository add(InputStream in, Charset charset) throws IOException {\n\t\ttry {\n\t\t\tRawConfigurationMetadata metadata = this.reader.read(in, charset);\n\t\t\treturn create(metadata);\n\t\t}\n\t\tcatch (IOException ex) {\n\t\t\tthrow ex;\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t\tthrow new IllegalStateException(\"Failed to read configuration metadata\", ex);\n\t\t}\n\t}\n\n\tprivate SimpleConfigurationMetadataRepository create(RawConfigurationMetadata metadata) {\n\t\tSimpleConfigurationMetadataRepository repository = new SimpleConfigurationMetadataRepository();\n\t\trepository.add(metadata.getSources());\n\t\tfor (ConfigurationMetadataItem item : metadata.getItems()) {\n\t\t\tConfigurationMetadataSource source = metadata.getSource(item);\n\t\t\trepository.add(item, source);\n\t\t}\n\t\tMap<String, ConfigurationMetadataProperty> allProperties = repository.getAllProperties();\n\t\tfor (ConfigurationMetadataHint hint : metadata.getHints()) {\n\t\t\tConfigurationMetadataProperty property = allProperties.get(hint.getId());\n\t\t\tif (property != null) {\n\t\t\t\taddValueHints(property, hint);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tString id = hint.resolveId();","sourceCodeStart":85,"sourceCodeEnd":121,"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#L85-L121","documentation":"Wrapped inside ConfigurationMetadataRepositoryJsonBuilder.add: when reading a JSON metadata stream, any non-IOException exception (i.e. a parsing/JSON format error from JsonReader) is rethrown as an IllegalStateException with this message and the original exception as cause. IOExceptions are rethrown unchanged; only format/structural problems get this wrapper.","triggerScenarios":"Passing an InputStream whose content is not valid configuration-metadata JSON - malformed JSON, missing required fields, wrong structure - so JsonReader.read throws a runtime exception (not IOException) during parsing, caught at line 102 and wrapped.","commonSituations":"A hand-edited or corrupted spring-configuration-metadata.json; a stream that returned an error page or HTML instead of JSON; a metadata file produced by an incompatible plugin version with a different schema; truncation of the stream.","solutions":["Inspect the cause exception (ex.getCause()) for the exact JSON/location error and fix the offending metadata file.","Validate the resource is a well-formed JSON document matching the configuration-metadata schema before feeding it to the builder.","Ensure the stream is not intercepted/corrupted (encoding, truncation) - read it fully and confirm Content-Length/charset."],"exampleFix":"// before\nbuilder.withJsonResource(corruptedOrHtmlStream).build();\n  -> IllegalStateException: Failed to read configuration metadata (cause: JsonParseException)\n// after\nString json = new String(stream.readAllBytes(), StandardCharsets.UTF_8);\n// validate json is the expected metadata document, then\nbuilder.withJsonResource(new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8))).build();","handlingStrategy":"try-catch","validationCode":"byte[] bytes = in.readAllBytes();\ntry (JsonParser p = JsonFactory.createParser(bytes)) {\n    while (p.nextToken() != null) { /* structural validation */ }\n}\nbuilder.withJsonResource(new ByteArrayInputStream(bytes));","typeGuard":"boolean looksLikeMetadataJson(byte[] b) {\n    String s = new String(b, StandardCharsets.UTF_8).trim();\n    return s.startsWith(\"{\") && (s.contains(\"\\\"groups\\\"\") || s.contains(\"\\\"properties\\\"\"));\n}","tryCatchPattern":"try { builder.withJsonResource(in).build(); }\ncatch (IllegalStateException ex) {\n    if (\"Failed to read configuration metadata\".equals(ex.getMessage())) {\n        Throwable cause = ex.getCause();\n        // log cause (e.g. JsonParseException with line/column), fix the file\n    } else throw ex;\n}","preventionTips":["Validate metadata JSON against the configuration-metadata schema before loading.","Never hand-edit generated metadata; regenerate via the annotation processor.","Check stream encoding/truncation; read fully and confirm it's JSON, not an error page."],"tags":["spring-boot","configuration-metadata","json","parsing"],"analyzedSha":"5b2dbdbb8be64415eb6552f81ff7c449c8d251e6","analyzedAt":"2026-08-04T18:53:14.967Z","schemaVersion":2}