diff --git a/src/hotspot/share/services/attachListener.cpp b/src/hotspot/share/services/attachListener.cpp index e3a6a034935..b57e357e897 100644 --- a/src/hotspot/share/services/attachListener.cpp +++ b/src/hotspot/share/services/attachListener.cpp @@ -127,9 +127,11 @@ public: // Called after the operation is completed. // If reply_writer is provided, writes the results. void complete() { - JavaThread* thread = JavaThread::current(); - ThreadBlockInVM tbivm(thread); - flush_reply(); + if (_reply_writer != nullptr) { + JavaThread* thread = JavaThread::current(); + ThreadBlockInVM tbivm(thread); + flush_reply(); + } } virtual void write(const char* str, size_t len) override {