Use AttachOperationFailedException instead of AttachNotSupportedException in findTargetProcessTmpDirectory

This commit is contained in:
Yasumasa Suenaga 2026-01-22 11:18:08 +09:00
parent 66a038afc4
commit 8e3caabcf1
2 changed files with 19 additions and 4 deletions

View File

@ -26,6 +26,7 @@ package sun.tools.attach;
import com.sun.tools.attach.AgentLoadException;
import com.sun.tools.attach.AttachNotSupportedException;
import com.sun.tools.attach.AttachOperationFailedException;
import com.sun.tools.attach.spi.AttachProvider;
import java.io.File;
@ -253,7 +254,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
return f;
}
private String findTargetProcessTmpDirectory(long pid) throws AttachNotSupportedException, IOException {
private String findTargetProcessTmpDirectory(long pid) throws IOException {
final var tmpOnProcPidRoot = PROC.resolve(Long.toString(pid)).resolve(ROOT_TMP);
/* We need to handle at least 4 different cases:
@ -279,7 +280,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
} else if (Files.isSameFile(tmpOnProcPidRoot, TMPDIR)) {
return TMPDIR.toString();
} else {
throw new AttachNotSupportedException("Unable to access the filesystem of the target process");
throw new AttachOperationFailedException("Unable to access the filesystem of the target process");
}
} catch (IOException ioe) {
try {
@ -297,7 +298,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
throw ioe;
} catch (MonitorException | URISyntaxException e) {
// Other exceptions (happened at MonitoredHost) would be wrapped with AttachNotSupportedException
throw new AttachNotSupportedException("Unable to find target proces", e);
throw new AttachOperationFailedException("Unable to find target proces", e);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -50,4 +50,18 @@ public class AttachOperationFailedException extends IOException {
public AttachOperationFailedException(String message) {
super(message);
}
/**
* Constructs an <code>AttachOperationFailedException</code> with
* the specified cause.
*
* @param message the detail message.
* @param cause the cause of this exception.
*
* @since 27
*/
public AttachOperationFailedException(String message, Throwable cause) {
super(message, cause);
}
}