{"record":{"id":"49ae8855d7e98006","repo":"eclipse-vertx/vert.x","slug":"asyncfile-must-only-be-used-in-the-context-that-cr","errorCode":null,"errorMessage":"AsyncFile must only be used in the context that created it, expected: ${context} actual ${vertx.getContext()}","messagePattern":"AsyncFile must only be used in the context that created it, expected: (.+?) actual (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/file/impl/AsyncFileImpl.java","lineNumber":519,"sourceCode":"      public void failed(Throwable t, Object attachment) {\n        promise.fail(t);\n      }\n    });\n  }\n\n  private void check() {\n    checkClosed();\n  }\n\n  private void checkClosed() {\n    if (closed) {\n      throw new IllegalStateException(\"File handle is closed\");\n    }\n  }\n\n  private void checkContext() {\n    if (!vertx.getContext().equals(context)) {\n      throw new IllegalStateException(\"AsyncFile must only be used in the context that created it, expected: \"\n          + context + \" actual \" + vertx.getContext());\n    }\n  }\n\n  private void doClose(Promise<Void> handler) {\n    context.<Void>executeBlockingInternal(() -> {\n      ch.close();\n      return null;\n    }).onComplete(handler);\n  }\n\n  private synchronized void closeInternal(Promise<Void> handler) {\n    check();\n\n    closed = true;\n\n    if (writesOutstanding == 0) {\n      doClose(handler);","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/file/impl/AsyncFileImpl.java#L501-L537","documentation":"Context guard in AsyncFileImpl.checkContext: the AsyncFile is being used from a different Vert.x context than the one that created it. AsyncFile operations are bound to their creating context's event loop; the message reports both the expected and actual context to identify the misuse.","triggerScenarios":"Thrown at vertx-core/src/main/java/io/vertx/core/file/impl/AsyncFileImpl.java:519 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use the AsyncFile only on the context (event loop) that created it","Pass data between contexts via eventBus or context.runOnContext instead of sharing the file object"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}