JDK-8044398 : Attach code should propagate errors in Diagnostic Commands as errors
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: svc
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2014-05-30
  • Updated: 2015-01-21
  • Resolved: 2014-05-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u40Fixed 9 b19Fixed
Related Reports
Relates :  
Description
The code in attachListener.cpp does this:

  DCmd::parse_and_execute(DCmd_Source_AttachAPI, out, op->arg(0), ' ', THREAD);
  if (HAS_PENDING_EXCEPTION) {
    java_lang_Throwable::print(PENDING_EXCEPTION, out);
    out->cr();
    CLEAR_PENDING_EXCEPTION;
    // The exception has been printed on the output stream
    // If the JVM returns JNI_ERR, the attachAPI throws a generic I/O
    // exception and the content of the output stream is not processed.
    // By returning JNI_OK, the exception will be displayed on the client side
  }
  return JNI_OK;

That was correct before the fix of JDK-8039173. After that fix, the attach framework is able to propagate error messages when an attach command fails.

The code in attachListener.cpp should be updated to:

  DCmd::parse_and_execute(DCmd_Source_AttachAPI, out, op->arg(0), ' ', THREAD);
  if (HAS_PENDING_EXCEPTION) {
    java_lang_Throwable::print(PENDING_EXCEPTION, out);
    out->cr();
    CLEAR_PENDING_EXCEPTION;
    return JNI_ERR;
  }
  return JNI_OK;