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

Inconsistent behavior with drag-and-drop of files on network shared drives

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10, Java 17.0.1 OpenJDK, JavaFX 17

      A DESCRIPTION OF THE PROBLEM :
      I see an odd behavior in JavaFX that I can't seem to explain or know how to resolve. My application involves importing files for processing. Users can either drag-and-drop files into the application, or use a standard browse dialog to select the files they want to import.

      Our clients have the files they are going to import located on shared network drives with really long pathnames. The application itself runs locally on their machine.

      The odd behavior is as follows:

      When a file with the long path name located on a shared network drive is selected using the standard browse dialog, it is detected and processed fine.

      When the same file is dragged from explorer into application, no file is detected and nothing happens.

      There are no problems with local files or with network files that have shorter path names. This problem appears when running on Windows 10 machines, but I don't know if it's limited to that OS.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Have a file on a shared network drive with a really long path name. Examples are given below:

      <link>

      <link>

      <link>

      Drag the file from the system's file explorer into the Java application

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      File is detected for processing in the drag-board's content
      ACTUAL -
      No file is available in the drag-board's content

      ---------- BEGIN SOURCE ----------
      package test;

      import java.io.File;
      import java.util.List;
      import java.util.stream.Collectors;
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Label;
      import javafx.scene.control.TextArea;
      import javafx.scene.input.TransferMode;
      import javafx.scene.layout.VBox;
      import javafx.stage.FileChooser;
      import javafx.stage.Stage;

      public class DnDTest extends Application {

      public static void main(final String[] args) {
      launch(args);
      }

      @Override
      public void start(final Stage stage) {
      final VBox container = new VBox();
      final VBox dndZone = new VBox();
      final TextArea txtArea = new TextArea();
      final var bttn = new Button("Browse");
      dndZone.getChildren().add(new Label("Drop files here..."));

      dndZone.setPrefSize(200, 100);
      container.getChildren().addAll(dndZone, txtArea, bttn);
      container.setSpacing(10);

      dndZone.setOnDragDropped(evt -> {
      final var files = evt.getDragboard().getFiles();
      // Does NOT work. files is EMPTY
      if (files != null)
      txtArea.setText(getText(files));
      });

      dndZone.setOnDragOver(evt -> evt.acceptTransferModes(TransferMode.ANY));
      dndZone.setOnDragEntered(evt -> evt.consume());
      dndZone.setOnDragExited(evt -> evt.consume());

      bttn.setOnAction(evt -> {
      final var fileChooser = new FileChooser();
      final var files = fileChooser.showOpenMultipleDialog(stage);
      // WORKS for the same file.
      if (files != null)
      txtArea.setText(getText(files));
      });

      final Scene scene = new Scene(container);
      stage.setScene(scene);
      stage.show();
      stage.sizeToScene();
      }

      private String getText(final List<File> files) {
      return files
      .stream()
      .map(f -> f.getName())
      .collect(Collectors.joining("\r\n"));
      }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            pnarayanaswa Praveen Narayanaswamy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: