'Inconsistent behavior with drag-and-drop of network files in JavaFX

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.
public class DnDTest {

    @Start
    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"));
    }
}

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.

Examples of some paths that cause issues are:

\\lab12jkd987.files.askon.ac.uk\Lab12Jkd987\Data\Microscopy\FixedCell\Joseph Diere\2022\2022_04_28_HMEC_FcRnGFPTransfected_FcRnAntagonists-AF555\2022_04_28_HMEC_FcRn-GFPTransfected_HAMsMediaOnly_1

\\lab12jkd987.files.askon.ac.uk\Lab12Jkd987\Data\Microscopy\FixedCell\Joseph Diere\2022\2022_04_13_BMDM_Dextran-AF555_JA01-AF647_Tf-AF488\2022_04_13_BMDM_Dextran-AF555p60c120_JA01-AF647p10c0_Tf-AF488p10c0-8

\\lab12jkd987.files.askon.ac.uk\Lab12Jkd987\Data\Microscopy\FixedCell\Joseph Diere\2022\2022_03_22 BMDM ReImaging_818C5+Mutants\2022_03_22 BMDM-M0_818C5-A647p10c0_JA03-A555p10c0_Tf488p10c0-9

Can anyone explain what is going on and how to get the behavior for the same file consistent between the two selection methods?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source