{"record":{"id":"7ad0eacf21165f0a","repo":"apache/maven","slug":"source-file-does-not-exist-or-is-not-a-file","errorCode":null,"errorMessage":"source file does not exist or is not a file","messagePattern":"source file does not exist or is not a file","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultTransport.java","lineNumber":102,"sourceCode":"            }\n        } catch (IOException e) {\n            throw new UncheckedIOException(e);\n        }\n    }\n\n    @Override\n    public Optional<String> getString(URI relativeSource, Charset charset) {\n        requireNonNull(charset, \"charset is null\");\n        Optional<byte[]> data = getBytes(relativeSource);\n        return data.map(bytes -> new String(bytes, charset));\n    }\n\n    @Override\n    public void put(Path source, URI relativeTarget) {\n        requireNonNull(source, \"source is null\");\n        requireNonNull(relativeTarget, \"relativeTarget is null\");\n        if (!Files.isRegularFile(source)) {\n            throw new IllegalArgumentException(\"source file does not exist or is not a file\");\n        }\n        if (relativeTarget.isAbsolute()) {\n            throw new IllegalArgumentException(\"Supplied URI is not relative\");\n        }\n        URI target = baseURI.resolve(relativeTarget);\n        if (!target.toASCIIString().startsWith(baseURI.toASCIIString())) {\n            throw new IllegalArgumentException(\"Supplied relative URI escapes baseUrl\");\n        }\n\n        PutTask putTask = new PutTask(target);\n        putTask.setDataPath(source);\n        try {\n            transporter.put(putTask);\n        } catch (Exception e) {\n            throw new RuntimeException(e);\n        }\n    }\n","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultTransport.java#L84-L120","documentation":"Transport.put(Path source, URI relativeTarget) requires the source to be an existing regular file (Files.isRegularFile). Directories, non-existent paths, and symlinks whose target is missing are rejected with IllegalArgumentException before any network I/O starts, because the underlying PutTask uploads one concrete file.","triggerScenarios":"Calling put(tempPath, uri) before the file was created; passing a directory Path; passing a Path whose symlink target was deleted; mixing up the two arguments and passing the target directory as source.","commonSituations":"Deploying an artifact whose JAR has not been built yet due to build-order mistakes; uploading immediately after Files.createTempFile but before writing content plus close; passing the wrong variable (target instead of source).","solutions":["Ensure the file is fully written and the stream closed before calling put","Guard the call with Files.isRegularFile(source) and fail fast with a clear message","If you meant to publish a directory, package it into a file (jar/zip) first"],"exampleFix":"// before: file not created yet\nPath jar = buildDir.resolve(\"app.jar\");\ntransport.put(jar, URI.create(\"com/acme/app/1.0/app-1.0.jar\"));\n\n// after: build, flush, verify, then upload\nFiles.createDirectories(buildDir);\nFiles.write(jar, bytes);\nif (!Files.isRegularFile(jar)) throw new IllegalStateException(\"artifact missing: \" + jar);\ntransport.put(jar, URI.create(\"com/acme/app/1.0/app-1.0.jar\"));","handlingStrategy":"validation","validationCode":"if (!Files.isRegularFile(source)) {\n    throw new IllegalStateException(\"upload source missing or not a file: \" + source);\n}\ntransport.put(source, relativeTarget);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Close and flush whatever wrote the file before uploading","In builds, put() only after the artifact-producing step completed","Never pass directories; package directories into jar/zip files first"],"tags":["maven","resolver","transport","file-upload","validation"],"backgroundTag":"file-not-found","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}