Skip to content

Commit de98dcf

Browse files
ctruedenimagejan
authored andcommitted
Fix NullPointerException when chooseFiles returns null
1 parent 1495881 commit de98dcf

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/main/java/org/scijava/ui/UserInterface.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ default File chooseFile(String title, File file, String style) {
193193
*
194194
* @param files The initial value displayed in the file chooser prompt.
195195
* @param filter A filter allowing to restrict file choice.
196-
* @return The selected {@link File}s chosen by the user, or null if prompt is not
197-
* available
196+
* @return The selected {@link File}s chosen by the user, or null if the
197+
* user cancels the prompt.
198198
*/
199199
default File[] chooseFiles(File[] files, FileFilter filter) {
200200
throw new UnsupportedOperationException();
@@ -205,12 +205,13 @@ default File[] chooseFiles(File[] files, FileFilter filter) {
205205
*
206206
* @param fileList The initial value displayed in the file chooser prompt.
207207
* @param filter A filter allowing to restrict file choice.
208-
* @return The selected {@link File}s chosen by the user, or null if prompt is not
209-
* available
208+
* @return The selected {@link File}s chosen by the user, or null if the
209+
* user cancels the prompt.
210210
*/
211211
default List<File> chooseFiles(List<File> fileList, FileFilter filter) {
212-
File[] files = fileList.toArray(new File[fileList.size()]);
213-
return Arrays.asList(chooseFiles(files, filter));
212+
final File[] initialFiles = fileList.toArray(new File[fileList.size()]);
213+
final File[] chosenFiles = chooseFiles(initialFiles, filter);
214+
return chosenFiles == null ? null : Arrays.asList(chosenFiles);
214215
}
215216

216217
/**

0 commit comments

Comments
 (0)