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

java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac

    Details

    • Subcomponent:
    • Resolved In Build:
      b36
    • CPU:
      x86_64
    • OS:
      os_x

      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)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]
      OS X 10.12.6


      A DESCRIPTION OF THE PROBLEM :
      Using java.awt.Desktop.moveToTrash(File), on Windows I get a confirmation dialog: "Are you sure you want to move this file to the Recycle bin". On OS X there is no confirmation dialog. Ideally there should be none on either, as that should be optional and implemented in Java code if necessary.

      From the source code I can also see that error messages will be displayed on Windows. Verifying deletion and displaying errors if necessary should also be left to the Java code.

      In awt_Desktop.cpp Java_sun_awt_windows_WDesktopPeer_moveToTrash() function,
         fop.fFlags = FOF_ALLOWUNDO;
      should be changed to
         fop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI;



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expect file to be deleted without prompting.
      ACTUAL -
      On Windows there is a "Are you sure you want to move this file to the Recycle bin" confirmation dialog.

      On OS X there is no confirmation dialog.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.*;
      import java.awt.Desktop;

      public class MoveToTrashTest {
         public static void main(String[] args) throws IOException {
            File f = File.createTempFile("mttTest", "txt");
            Desktop.getDesktop().moveToTrash(f);
         }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use JNI to move files to trash on Windows.

        Attachments

          Activity

            People

            • Assignee:
              sveerabhadra Shashidhara Veerabhadraiah (Inactive)
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: