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

selecting a file from filechooser with unicode characters in the file path truncates file path or wrong path

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: openjfx15
    • Fix Version/s: None
    • Component/s: javafx
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      linux_ubuntu

      Description

      ADDITIONAL SYSTEM INFORMATION :
      System:
      Ubuntu 20.04 LTS (5.4.0-58-generic, x64),

      Java:
      openjdk 15.0.1 2020-10-20
      OpenJDK Runtime Environment AdoptOpenJDK (build 15.0.1+9)
      OpenJDK 64-Bit Server VM AdoptOpenJDK (build 15.0.1+9, mixed mode, sharing)

      Other:
      OpenJFX 15.0.1

      A DESCRIPTION OF THE PROBLEM :
      If one uses the FileChooser (https://openjfx.io/javadoc/15/javafx.graphics/javafx/stage/FileChooser.html) class to select an existing file from the file system with certain unicode characters in the real file path, the path of the returned File object is wrong.

      For example, if the real file path is "/foo/🍀/bar.file", the returned File object of the FileChooser has the path "/foo/🍀/bar.f".



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Open a file chooser dialogue
      2. Select a file, which has at least one Character from the Miscellaneous Symbols and Pictographs Block in the file path

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The returned file object contains the correctly encoded and complete path.
      ACTUAL -
      The returned file object contains a wrongly encoded and truncated path.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.stage.FileChooser;
      import javafx.stage.Stage;

      import java.io.IOException;
      import java.nio.file.Files;
      import java.nio.file.Path;
      import java.util.UUID;

      /**
       * Test App for JavaFX Bug
       */
      public class App extends Application {

      private static final String PROBLEMATIC_CHAR = "\uD83C\uDF40"; //FOUR LEAF CLOVER
      private static final String tmpDir = System.getProperty("java.io.tmpdir");

      private static Path workingDir;
      private static Path expectedFile;

      @Override
      public void start(Stage stage) {
      var fileChooser = new FileChooser();
      fileChooser.setInitialDirectory(workingDir.toFile());
      var chosenFile = fileChooser.showOpenDialog(stage);
      if (chosenFile != null) {
      if (!chosenFile.toPath().equals(expectedFile)) {
      throw new IllegalStateException("Chosen path is not correct: " + chosenFile.getPath());
      }
      }
      stage.close();
      System.exit(0);
      }

      private static void prepare() throws IOException {
      var dir = Files.createDirectories(Path.of(tmpDir).resolve(UUID.randomUUID()+"/" + PROBLEMATIC_CHAR));
      workingDir = dir.getParent();
      expectedFile = Files.createFile(dir.resolve("foo"));
      }

      public static void main(String[] args) throws IOException {
      assert tmpDir != null;
      prepare();
      assert workingDir != null;
      launch();
      }

      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: