RFR: 8376052: Use AttachOperationFailedException rather than AttachNotSupportedException in findTargetProcessTmpDirectory() [v2]
Alan Bateman
alanb at openjdk.org
Sun Jan 25 08:26:52 UTC 2026
On Thu, 22 Jan 2026 13:47:27 GMT, Yasumasa Suenaga <ysuenaga at openjdk.org> wrote:
>> Can you please provide an example where IOException is thrown? The code in the catch block to use MonitoredHost.getMonitoredHost is surprising (the only dependency on jvmstat should be in the enumerate/list implementation).
>>
>> If URISyntaxException is not possible then it would be okay to throw an AssertionError or InternalError here.
>>
>> It would be useful to get an example or two of when MonitorException is thrown. That seems a reason candidate to wrap in an AttachOperationFailedException but I think have a specific example or two would help the discussion.
>>
>> It would be good to re-flow the comment in findTargetProcessTmpDirectory to reduce the wildly long lines. Right now it is really hard to look at the changes side-by-side.
>
>> Can you please provide an example where IOException is thrown?
>
> I could not produce IOException, but it might occur if filesystem is broken.
> AccessDeniedException would happen as following. We can see it easy on attach to rootless container.
>
> # ./jcmd 1 VM.version
> 1:
> java.nio.file.AccessDeniedException: /proc/1/root/tmp
> at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
> at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:108)
> at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:113)
> at java.base/sun.nio.fs.UnixFileSystemProvider.isSameFile(UnixFileSystemProvider.java:391)
> at java.base/java.nio.file.Files.isSameFile(Files.java:1418)
> at jdk.attach/sun.tools.attach.VirtualMachineImpl.findTargetProcessTmpDirectory(VirtualMachineImpl.java:280)
> at jdk.attach/sun.tools.attach.VirtualMachineImpl.findSocketFile(VirtualMachineImpl.java:236)
> at jdk.attach/sun.tools.attach.VirtualMachineImpl.<init>(VirtualMachineImpl.java:87)
> at jdk.attach/sun.tools.attach.AttachProviderImpl.attachVirtualMachine(AttachProviderImpl.java:56)
> at jdk.attach/com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:201)
> at jdk.jcmd/sun.tools.jcmd.JCmd.executeCommandForPid(JCmd.java:113)
> at jdk.jcmd/sun.tools.jcmd.JCmd.main(JCmd.java:97)
>
>
>> It would be useful to get an example or two of when MonitorException is thrown.
>
> As I said before, I cannot find out the location to throw MonitorException in JDK source around attach mechanism, but it might happen if the user uses custom attach provider. Anyway it is checked exception, so it shouldn't ignore or raise assertion error.
Okay, I think we can go with wrapping these exceptions with AttachOperationFailedException.
Are you planning to re-flow/cleanup findTargetProcessTmpDirectory as part of this PR?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/29355#discussion_r2725111955
More information about the serviceability-dev
mailing list