{"record":{"id":"d846004a326d3ca5","repo":"testcontainers/testcontainers-java","slug":"folder-like-containerpath-in-copyfiletocontainer-is","errorCode":null,"errorMessage":"folder-like containerPath in copyFileToContainer is deprecated, please explicitly specify a file path","messagePattern":"folder-like containerPath in copyFileToContainer is deprecated, please explicitly specify a file path","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/src/main/java/org/testcontainers/containers/ContainerState.java","lineNumber":326,"sourceCode":"     */\n    default Container.ExecResult execInContainer(Charset outputCharset, ExecConfig execConfig)\n        throws UnsupportedOperationException, IOException, InterruptedException {\n        return ExecInContainerPattern.execInContainer(getDockerClient(), getContainerInfo(), outputCharset, execConfig);\n    }\n\n    /**\n     *\n     * Copies a file or directory to the container.\n     *\n     * @param mountableFile file or directory which is copied into the container\n     * @param containerPath destination path inside the container\n     */\n    default void copyFileToContainer(MountableFile mountableFile, String containerPath) {\n        File sourceFile = new File(mountableFile.getResolvedPath());\n\n        if (containerPath.endsWith(\"/\") && sourceFile.isFile()) {\n            final Logger logger = LoggerFactory.getLogger(GenericContainer.class);\n            logger.warn(\n                \"folder-like containerPath in copyFileToContainer is deprecated, please explicitly specify a file path\"\n            );\n            copyFileToContainer((Transferable) mountableFile, containerPath + sourceFile.getName());\n        } else {\n            copyFileToContainer((Transferable) mountableFile, containerPath);\n        }\n    }\n\n    /**\n     *\n     * Copies a file to the container.\n     *\n     * @param transferable file which is copied into the container\n     * @param containerPath destination path inside the container\n     */\n    @SneakyThrows({ IOException.class, InterruptedException.class })\n    default void copyFileToContainer(Transferable transferable, String containerPath) {\n        if (getContainerId() == null) {","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/containers/ContainerState.java#L308-L344","documentation":"ContainerState.copyFileToContainer warns when a file is copied to a container path ending in '/' (a folder-like path). Historically this appended the file name implicitly; now that behavior is deprecated and users should pass the explicit destination file path. The copy still succeeds with the file name appended.","triggerScenarios":"Calling copyFileToContainer(mountableFile, \"/some/dir/\") where mountableFile resolves to a regular file and the containerPath ends with a slash.","commonSituations":"Copy-pasted path constants meant for directory mounting being reused for single-file copies; transitioning code from folder mounts to file copies.","solutions":["Append the file name to the containerPath explicitly instead of relying on the trailing slash","Drop the trailing slash and give the full destination file path"],"exampleFix":"// before\ncontainer.copyFileToContainer(MountableFile.forHostPath(\"app.properties\"), \"/etc/app/\");\n// after\ncontainer.copyFileToContainer(MountableFile.forHostPath(\"app.properties\"), \"/etc/app/app.properties\");","handlingStrategy":"validation","validationCode":"void copyFile(GenericContainer<?> c, MountableFile f, String containerPath) {\n    if (containerPath.endsWith(\"/\")) {\n        String fileName = new File(f.getResolvedPath()).getName();\n        containerPath = containerPath + fileName;\n    }\n    c.copyFileToContainer(f, containerPath);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never end copyFileToContainer paths with '/' for files","Always pass the full destination file path including the file name","Search the codebase for copyFileToContainer calls with trailing slashes"],"tags":["deprecated","file-copy","container","api-usage"],"backgroundTag":"deprecated-api-usage","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"}