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

java.awt.Desktop.moveToTrash(File) should not throw runtime exception for missing file

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "9.0.1"
      Java(TM) SE Runtime Environment (build 9.0.1+11)
      Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      If the file being deleted does not exist, java.awt.Desktop.moveToTrash(File) throws IllegalArgumentException. This is not sensible. Even if the code tests for file existence before the call, the file could be deleted externally between that test and the test in moveToTrash(). Thus, for reliable code any call to moveToTrash must be in a try/catch with IllegalArgumentException caught.

      If the file does not exist, either no exception should be thrown or a checked exception should be thrown. Since the API is already public, it may make the most sense to just not throw the exception and silently ignore the non-existent file.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      Use try/catch and catch IllegalArgumentException for any call to Desktop.moveToTrash()

        Attachments

          Activity

            People

            • Assignee:
              serb Sergey Bylokhov
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: