{"record":{"id":"a823c52a4db6deaf","repo":"testcontainers/testcontainers-java","slug":"could-not-load-classpath-init-script-initscriptpath-a823c5","errorCode":null,"errorMessage":"Could not load classpath init script: ${initScriptPath}","messagePattern":"Could not load classpath init script: (.+?)","errorType":"exception","errorClass":"ScriptLoadException","httpStatus":null,"severity":"error","filePath":"modules/database-commons/src/main/java/org/testcontainers/ext/ScriptUtils.java","lineNumber":216,"sourceCode":"     * @param initScriptPath   the resource to load the init script from\n     */\n    public static void runInitScript(DatabaseDelegate databaseDelegate, String initScriptPath) {\n        try {\n            URL resource = Thread.currentThread().getContextClassLoader().getResource(initScriptPath);\n            if (resource == null) {\n                resource = ScriptUtils.class.getClassLoader().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            }\n            String scripts = IOUtils.toString(resource, StandardCharsets.UTF_8);\n            executeDatabaseScript(databaseDelegate, initScriptPath, scripts);\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 UncategorizedScriptException(\"Error while executing init script: \" + initScriptPath, e);\n        }\n    }\n\n    public static void executeDatabaseScript(DatabaseDelegate databaseDelegate, String scriptPath, String script)\n        throws ScriptException {\n        executeDatabaseScript(\n            databaseDelegate,\n            scriptPath,\n            script,\n            false,\n            false,\n            DEFAULT_COMMENT_PREFIX,\n            DEFAULT_STATEMENT_SEPARATOR,\n            DEFAULT_BLOCK_COMMENT_START_DELIMITER,\n            DEFAULT_BLOCK_COMMENT_END_DELIMITER","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/database-commons/src/main/java/org/testcontainers/ext/ScriptUtils.java#L198-L234","documentation":"ScriptUtils.runInitScript found the init script resource but failed to read it: an IOException occurred (e.g. in IOUtils.toString), and it wraps it in ScriptLoadException with this message. Unlike error 104, the resource exists but its content could not be loaded.","triggerScenarios":"IOUtils.toString(resource, UTF_8) throwing IOException: unreadable resource stream, underlying jar/zip corruption, or I/O failure while opening the URL connection to the classpath resource.","commonSituations":"Reading scripts from a fat-jar with a corrupted entry; permissions problems on the resources directory; a custom classloader returning a URL that can't be opened.","solutions":["Inspect the wrapped IOException cause for the underlying I/O problem.","Rebuild the project / clear stale build artifacts to fix corrupted packaged resources.","Verify file read permissions on the resources directory.","Confirm the resource loads in a plain unit test before using it in container setup."],"exampleFix":"// before\nURL url = getClass().getResource(\"/init.sql\"); // from a corrupt jar\n// after\n// rebuild: mvn clean package, then rerun the tests","handlingStrategy":"try-catch","validationCode":"URL url = Thread.currentThread().getContextClassLoader().getResource(initScriptPath);\ntry (InputStream in = url.openStream()) {\n    in.readAllBytes(); // fails fast with a clear IOException if unreadable\n}","typeGuard":null,"tryCatchPattern":"try {\n    ScriptUtils.runInitScript(delegate, initScriptPath);\n} catch (ScriptLoadException e) {\n    if (e.getCause() instanceof IOException) {\n        // resource exists but couldn't be read: check jar integrity/permissions\n    }\n    throw e;\n}","preventionTips":["Run clean builds if resources come from packaged jars.","Check read permissions on the resources directory in CI workspaces.","Pre-reading the resource in a smoke test surfaces I/O problems early."],"tags":["io","init-script","classpath","script-load"],"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"}