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

JFileChooser - empty (0 bytes) file is displayed as 1 KB

    XMLWordPrintable

Details

    • b20
    • x86_64
    • linux

    Description

      ADDITIONAL SYSTEM INFORMATION :
      "Previously worked in the Release": Never worked?

      * Linux: bug
      * Windows: OK?
      * Probably any Java version

      A DESCRIPTION OF THE PROBLEM :
      An empty (0 bytes) file is displayed as 1 KB in the "Details" view.

      File choosers in other UI toolkits (Qt, GTK, native win32) display the size
      correctly as "0 B" or "0 bytes".

      There is a suspicious line in src/java.desktop/share/classes/sun/swing/FilePane.java:

      MessageFormat.format(kiloByteString, (len == 0L) ? 1L : len);

      REGRESSION : Last worked in version 8

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      0. Screenshot: https://i.imgur.com/1LguaBq.png
      1. Run the attached test on *Linux*
      2. Click the "Details" button in right-top corner
      3. Size of the "TEST-EMPTY-FILE.txt" is displayed as "1 KB" instead of "0 KB"
         (other sizes are displayed correctly - probably)

      Note that Metal Look And Feel on *MS Windows* displays "0 bytes",
      because it uses ShellFolder to set column values.


      ---------- BEGIN SOURCE ----------
      import java.io.IOException;
      import java.nio.file.Files;
      import java.nio.file.Path;
      import javax.swing.JFileChooser;
      import javax.swing.SwingUtilities;

      public class Test {

      public static void main(String[] args) throws IOException {

      Path currentDir = Path.of(System.getProperty("user.dir"));

      // create empty file

      Path emptyFile = currentDir.resolve("TEST-EMPTY-FILE.txt");

      if (!Files.exists(emptyFile)) {
      System.out.println("Creating " + emptyFile);
      Files.createFile(emptyFile);
      }

      // show file chooser

      SwingUtilities.invokeLater(() -> {
      JFileChooser fc = new JFileChooser();
      fc.setCurrentDirectory(currentDir.toFile());
      fc.showOpenDialog(null);
      });
      }

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

      FREQUENCY : always


      Attachments

        1. From_submitter.PNG
          From_submitter.PNG
          85 kB
        2. Test.java
          0.7 kB
        3. Ubuntu20.04.PNG
          Ubuntu20.04.PNG
          43 kB
        4. Windows10.PNG
          Windows10.PNG
          58 kB

        Issue Links

          Activity

            People

              abhiscxk Abhishek Kumar
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: