JDK-8163526 : protect FileChooser return from internal NPE
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: 8,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-08-09
  • Updated: 2020-01-31
  • Resolved: 2016-08-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u152Fixed 9Fixed
Related Reports
Duplicate :  
Description
On Windows, it is possible to select a .url that turns into a NULL as it is returned. Add a simple check in modules/javafx.graphics/src/main/java/com/sun/glass/ui/CommonDialogs.java to drop any null values.


Comments
Approved to backport to 8u-dev for 8u122
10-08-2016

Changeset: 6f8b4d12b00d Author: ddhill Date: 2016-08-10 14:55 -0400 URL: http://hg.openjdk.java.net/openjfx/9-dev/rt/rev/6f8b4d12b00d 8163526: protect FileChooser return from internal NPE Reviewed-by: kcr ! modules/javafx.graphics/src/main/java/com/sun/glass/ui/CommonDialogs.java
10-08-2016

+1 (I will separately comment on whether to approve the backport)
10-08-2016

I agree in this case, especially since we might backport this to JDK 8 and we have deliberately avoided using streams in shared code in FX for JDK 8.
10-08-2016

[~vlipatov] Vadim, Wow...... It took me several passes to understand what that one line was doing. :-) I think I would prefer the old school plus simple null check for now.
10-08-2016

David, how about: List<File> list = Arrays.stream(files).filter(Objects::nonNull).map(File::new).collect(Collectors.toList()); ?
10-08-2016

This would be worth a back port to 8, as it is small, and was seen in the wild.
10-08-2016

Simple diff - diff --git a/modules/javafx.graphics/src/main/java/com/sun/glass/ui/CommonDialogs.java b/modules/javafx.graphics/src/main/java/com/sun/glass/ui/CommonDialogs.java --- a/modules/javafx.graphics/src/main/java/com/sun/glass/ui/CommonDialogs.java +++ b/modules/javafx.graphics/src/main/java/com/sun/glass/ui/CommonDialogs.java @@ -252,7 +252,9 @@ { List<File> list = new ArrayList<File>(); for (String s : files) { - list.add(new File(s)); + if (s != null) { + list.add(new File(s)); + } } return new FileChooserResult(list, extensionFilters == null || index < 0 || index >= extensionFilters.length ?
10-08-2016