{"record":{"id":"4c0d00d5f4b6da67","repo":"eclipse-vertx/vert.x","slug":"not-a-streaming-upload","errorCode":null,"errorMessage":"Not a streaming upload","messagePattern":"Not a streaming upload","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/http/impl/HttpServerFileUploadImpl.java","lineNumber":203,"sourceCode":"          if (!cancelled) {\n            file = f;\n            return context.succeededFuture();\n          }\n          fs.delete(filename);\n          return context.failedFuture(\"Streaming aborted\");\n        }\n      }, err -> {\n        fs.delete(filename);\n        return context.failedFuture(err);\n      });\n    });\n  }\n\n  @Override\n  public boolean cancelStreamToFileSystem() {\n    synchronized (this) {\n      if (pipe == null) {\n        throw new IllegalStateException(\"Not a streaming upload\");\n      }\n      if (file != null) {\n        return false;\n      }\n      cancelled = true;\n    }\n    pipe.close();\n    return true;\n  }\n\n  @Override\n  public synchronized boolean isSizeAvailable() {\n    return !lazyCalculateSize;\n  }\n\n  @Override\n  public synchronized AsyncFile file() {\n    return file;","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/http/impl/HttpServerFileUploadImpl.java#L185-L221","documentation":"HttpServerFileUploadImpl.cancelStreamToFileSystem() cancels an in-progress streaming upload to disk. The upload only has an internal pipe when it was started with toFilesystem streaming (streamingToFileSync); if the upload was buffered in memory or no streaming-to-file was ever started, pipe is null and this IllegalStateException is thrown because there is nothing to cancel.","triggerScenarios":"Calling cancelStreamToFileSystem() on an upload whose body is being buffered in memory (no streaming to a file was initiated), or after the streaming upload already completed/never started.","commonSituations":"Applications that call cancel on every upload in an uploadHandler regardless of whether the upload is streaming to a file; canceling after the upload finished so file is already set returns false instead (no exception), but canceling a non-streaming upload throws.","solutions":["Only call cancelStreamToFileSystem() on uploads for which a streaming file target was requested (e.g. upload.streamToFileSystem(...) was called and is still in progress)","Check the upload state before canceling; if it is not streaming, simply discard it (e.g. stream to null/buffer) instead","Wrap the cancel call in a try/catch for IllegalStateException when upload streaming mode is not known in advance"],"exampleFix":"// before\nupload.cancelStreamToFileSystem(); // throws if upload is not streaming to a file\n\n// after\ntry {\n  boolean cancelled = upload.cancelStreamToFileSystem();\n} catch (IllegalStateException e) {\n  // upload is not a streaming-to-file upload; discard it another way\n  upload.handler(buf -> {});\n  upload.endHandler(v -> {});\n}","handlingStrategy":"try-catch","validationCode":"// Track whether you started streaming to a file\nboolean streamingToFile = startedStreamToFileSystem;\nif (streamingToFile && upload.cancelStreamToFileSystem() == false) {\n  // file already written; cancel too late\n}","typeGuard":null,"tryCatchPattern":"try {\n  upload.cancelStreamToFileSystem();\n} catch (IllegalStateException e) {\n  // not a streaming upload; discard via handlers instead\n}","preventionTips":["Only cancel uploads you explicitly started with streamToFileSystem","Cancel while the upload is in progress, not after completion","Model upload state explicitly in your application code"],"tags":["http","file-upload","illegal-state"],"backgroundTag":"invalid-state-transition","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}