{"record":{"id":"cf670b43117f1489","repo":"testcontainers/testcontainers-java","slug":"could-not-load-classpath-init-script-initscriptpath","errorCode":null,"errorMessage":"Could not load classpath init script: ${initScriptPath}","messagePattern":"Could not load classpath init script: (.+?)","errorType":"exception","errorClass":"org.testcontainers.ext.ScriptUtils.ScriptLoadException","httpStatus":null,"severity":"error","filePath":"modules/cassandra/src/main/java/org/testcontainers/containers/CassandraContainer.java","lineNumber":111,"sourceCode":"    /**\n     * Load init script content and apply it to the database if initScriptPath is set\n     */\n    private void runInitScriptIfRequired() {\n        if (initScriptPath != null) {\n            try {\n                URL resource = Thread.currentThread().getContextClassLoader().getResource(initScriptPath);\n                if (resource == null) {\n                    logger().warn(\"Could not load classpath init script: {}\", initScriptPath);\n                    throw new ScriptLoadException(\n                        \"Could not load classpath init script: \" + initScriptPath + \". Resource not found.\"\n                    );\n                }\n                String cql = IOUtils.toString(resource, StandardCharsets.UTF_8);\n                DatabaseDelegate databaseDelegate = getDatabaseDelegate();\n                ScriptUtils.executeDatabaseScript(databaseDelegate, initScriptPath, cql);\n            } catch (IOException e) {\n                logger().warn(\"Could not load classpath init script: {}\", initScriptPath);\n                throw new ScriptLoadException(\"Could not load classpath init script: \" + initScriptPath, e);\n            } catch (ScriptException e) {\n                logger().error(\"Error while executing init script: {}\", initScriptPath, e);\n                throw new ScriptUtils.UncategorizedScriptException(\n                    \"Error while executing init script: \" + initScriptPath,\n                    e\n                );\n            }\n        }\n    }\n\n    /**\n     * Map (effectively replace) directory in Docker with the content of resourceLocation if resource location is not null\n     *\n     * Protected to allow for changing implementation by extending the class\n     *\n     * @param pathNameInContainer path in docker\n     * @param resourceLocation    relative classpath to resource\n     */","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/cassandra/src/main/java/org/testcontainers/containers/CassandraContainer.java#L93-L129","documentation":"After locating the init script resource, CassandraContainer reads its CQL content with IOUtils.toString. If reading the stream throws an IOException (unreadable/broken resource), the container throws ScriptLoadException wrapping it, logging 'Could not load classpath init script: <path>'.","triggerScenarios":"runInitScriptIfRequired during container.start() when the classpath resource for initScriptPath was found but its content could not be read (IOException from IOUtils.toString).","commonSituations":"Corrupted or unreadable resource in a jar; resource filtered/binary-corrupted by build plugins; charset/IO issues in packaged artifacts.","solutions":["Rebuild the project and inspect the packaged resource in target/test-classes or the jar","Disable aggressive Maven resource filtering for .cql files (nonFilteredFileExtensions) so the file isn't corrupted","Ensure the file is plain UTF-8 text and readable by the test process"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(initScript)) {\n  if (in == null || in.read() == -1) throw new IllegalStateException(\"init script empty or unreadable\");\n}","typeGuard":null,"tryCatchPattern":"try { container.start(); } catch (ContainerLaunchException e) { /* inspect ScriptLoadException cause (IOException) */ }","preventionTips":["Keep init scripts as plain UTF-8 text in resources","Disable resource filtering for .cql files in Maven","Rebuild and verify packaged artifacts after editing scripts"],"tags":["cassandra","testcontainers","io","file-read-failed","init-script"],"backgroundTag":"file-read-failed","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}