Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8358088

Attach API: VirtualMachineImpl should use try with resources on Files::lines()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • None
    • core-svc

      As reported on the mailing list: https://mail.openjdk.org/pipermail/serviceability-dev/2025-May/063907.html


      sun.tools.attach.VirtualMachineImpl#checkCatchesAndSendQuitTo is not following the API Note advice in java.nio.file.Files for the lines() method.

      final var cmdline = Files.lines(procPid.resolve("cmdline")).findFirst();

      https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/nio/file/Files.html#lines(java.nio.file.Path)

      API Note:
      This method must be used within a try-with-resources statement or similar control structure to ensure that the stream's open file is closed promptly after the stream's operations have completed.

            lcable Larry Cable
            kevinw Kevin Walls
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: