{"record":{"id":"7b3de5608b551d21","repo":"spring-projects/spring-boot","slug":"failed-to-read","errorCode":null,"errorMessage":"Failed to read '{}'","messagePattern":"Failed to read '(.+?)'","errorType":"exception","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java","lineNumber":125,"sourceCode":"\t}\n\n\t@Override\n\tpublic Class<? extends Plugin<Project>> getPluginClass() {\n\t\treturn ApplicationPlugin.class;\n\t}\n\n\tprivate String loadResource(String name) {\n\t\ttry (InputStreamReader reader = new InputStreamReader(getResourceAsStream(name))) {\n\t\t\tchar[] buffer = new char[4096];\n\t\t\tint read;\n\t\t\tStringWriter writer = new StringWriter();\n\t\t\twhile ((read = reader.read(buffer)) > 0) {\n\t\t\t\twriter.write(buffer, 0, read);\n\t\t\t}\n\t\t\treturn writer.toString();\n\t\t}\n\t\tcatch (IOException ex) {\n\t\t\tthrow new GradleException(\"Failed to read '\" + name + \"'\", ex);\n\t\t}\n\t}\n\n\tprivate InputStream getResourceAsStream(String name) {\n\t\tInputStream stream = getClass().getResourceAsStream(name);\n\t\tAssert.state(stream != null, \"Resource '%s' not found'\".formatted(name));\n\t\treturn stream;\n\t}\n\n\tprivate void configureFilePermissions(CopySpec copySpec, int mode) {\n\t\tif (GradleVersion.current().compareTo(GradleVersion.version(\"8.3\")) >= 0) {\n\t\t\tcopySpec.filePermissions((filePermissions) -> filePermissions.unix(Integer.toString(mode, 8)));\n\t\t}\n\t\telse {\n\t\t\tconfigureFileMode(copySpec, mode);\n\t\t}\n\t}\n","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/270dfe353fb830fd69b823a8a859287ff103854b/build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java#L107-L143","documentation":"Thrown by ApplicationPluginAction.loadResource when an IOException occurs while reading a bundled classpath resource (e.g. a default start-script template) character-by-character into a StringWriter. The resource was located successfully (getResourceAsStream returned non-null, otherwise Assert.state would fire first), but the read loop itself failed partway. This is an internal plugin resource read, not a user file.","triggerScenarios":"Calling any Gradle task that triggers ApplicationPluginAction configuration (e.g. startScripts, installDist) when the JVM experiences an I/O interruption while reading the plugin's own bundled resource. The try-with-resources InputStreamReader.read(buffer) throws IOException inside the while loop.","commonSituations":"A corrupted or truncated plugin JAR (resource present in the index but unreadable), a custom ClassLoader that returns a broken stream, JVM running low on file descriptors, or the plugin JAR being replaced/modified while Gradle is still running. Extremely rare in normal operation since the resource is packaged inside the plugin itself.","solutions":["Clean and refresh the Gradle dependencies: run 'gradle --refresh-dependencies' to re-download a non-corrupt spring-boot-gradle-plugin JAR.","Clear the Gradle caches for the plugin: remove ~/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-gradle-plugin and re-resolve.","Verify the plugin JAR is not being shadowed or modified by a custom ClassLoader or fat-JAR packaging in the build.","Check for filesystem-level issues (disk full, NFS hiccup) if the error appears intermittently."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check that the resource exists and is openable before the read loop.\n// Note: this guards resource presence, not read-time I/O failures.\ntry (var probe = getClass().getResourceAsStream(name)) {\n    if (probe == null) {\n        throw new IllegalStateException(\"Resource not found: \" + name);\n    }\n} catch (IOException ex) {\n    // resource unreadable even for a probe — abort early\n}","typeGuard":null,"tryCatchPattern":"// Recommended: catch GradleException around task execution and surface the cause.\ntry {\n    project.getTasks().named(\"startScripts\").get().getActions().forEach(a -> a.execute(task));\n} catch (GradleException ex) {\n    if (ex.getMessage() != null && ex.getMessage().startsWith(\"Failed to read '\")) {\n    //     handle corrupted plugin resource — refresh dependencies\n        throw new GradleException(\"Plugin resource unreadable. Run 'gradle --refresh-dependencies'.\", ex);\n    }\n    throw ex;\n}","preventionTips":["Pin the Spring Boot plugin version explicitly to avoid pulling a corrupt SNAPSHOT.","Use 'gradle --refresh-dependencies' after plugin upgrades to re-fetch JARs.","Avoid modifying or shading the spring-boot-gradle-plugin JAR at runtime."],"tags":["gradle","resource-loading","io","spring-boot-plugin","internal"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}