RFR: 8288882: JFileChooser - empty (0 bytes) file is displayed as 1 KB [v17]
Alexey Ivanov
aivanov at openjdk.org
Thu Aug 11 19:35:48 UTC 2022
On Thu, 11 Aug 2022 10:02:56 GMT, Abhishek Kumar <duke at openjdk.org> wrote:
>> JFileChooser - empty file size issue fixed.
>> For empty file, now the size 0 KB.
>> Manual Test Case "FileSizeCheck.java" created.
>
> Abhishek Kumar has updated the pull request incrementally with one additional commit since the last revision:
>
> Smaller file sizes display one decimal precision
Also, please update the copyright year in `FilePane.java`.
src/java.desktop/share/classes/sun/swing/FilePane.java line 535:
> 533: gigaByteString = UIManager.getString("FileChooser.fileSizeGigaBytes", l);
> 534: fullRowSelection = UIManager.getBoolean("FileView.fullRowSelection");
> 535:
Can this blank line remain?
src/java.desktop/share/classes/sun/swing/FilePane.java line 1129:
> 1127: double baseFileSize = 1000.0;
> 1128: MessageFormat mf = new MessageFormat("");
> 1129: NumberFormat nf = NumberFormat.getNumberInstance();
All three can be `final`.
src/java.desktop/share/classes/sun/swing/FilePane.java line 1199:
> 1197: } else if (value instanceof Long len) {
> 1198: if (listViewWindowsStyle) {
> 1199: updateMessageFormatPattern(kiloByteString, 1);
Now you always call `updateMessageFormatPattern` with 1 as the second parameter. Maybe you could initialise both MessageFormat and NumberFormat once and then just use the objects. Or switch back to `MessageFormat.format` method.
src/java.desktop/share/classes/sun/swing/FilePane.java line 1206:
> 1204: } else {
> 1205: double kbVal = formatToDoubleValue(len);
> 1206: objs[0] = Double.valueOf(kbVal);
You can assign `double` directly without explicit boxing with `Double.valueOf`.
Suggestion:
objs[0] = 0.0;
} else if (len > 0 && len < 100L) {
objs[0] = 0.1;
} else {
objs[0] = formatToDoubleValue(len);
IDE highlights each line with such usage.
test/jdk/javax/swing/JFileChooser/FileSizeCheck.java line 50:
> 48: private static JFrame frame;
> 49: private static JFileChooser fc;
> 50: private static PassFailJFrame passFailJFrame;
These three fields can be local variables.
test/jdk/javax/swing/JFileChooser/FileSizeCheck.java line 51:
> 49: private static JFileChooser fc;
> 50: private static PassFailJFrame passFailJFrame;
> 51: private static Path [] tempFilePaths;
Suggestion:
private static Path[] tempFilePaths;
No space before brackets in array declaration. In other places too.
test/jdk/javax/swing/JFileChooser/FileSizeCheck.java line 78:
> 76: PassFailJFrame.positionTestWindow(frame, PassFailJFrame.Position.HORIZONTAL);
> 77: // create temp files
> 78:
The comment applies to `try` block. The blank line should be above the comment. Please start comments with a capital letter.
test/jdk/javax/swing/JFileChooser/FileSizeCheck.java line 98:
> 96: }
> 97:
> 98: public static void main(String args[]) throws InterruptedException,
Use Java-style array declarations:
Suggestion:
public static void main(String[] args) throws InterruptedException,
-------------
Changes requested by aivanov (Reviewer).
PR: https://git.openjdk.org/jdk/pull/9327
More information about the client-libs-dev
mailing list