Skip to content

Commit e6e1fe9

Browse files
committed
Safeguard against null style arg in UserInterface#chooseFile
This fixes the issue reported by @kephale on the forum, where the absence of a style attribute on a File parameter leads to a NullPointerException: https://forum.image.sc/t/error-for-file-type-imagej2-parameter/25585 This commit is a quick fix, it should probably be rewritten when addressing issue #333
1 parent 2201d40 commit e6e1fe9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,12 @@ DialogPrompt dialogPrompt(String message, String title,
162162
*/
163163
default File chooseFile(final File file, final String style) {
164164
final String title;
165-
if (style.equals(FileWidget.DIRECTORY_STYLE)) title = "Choose a directory";
166-
else if (style.equals(FileWidget.OPEN_STYLE)) title = "Open";
167-
else if (style.equals(FileWidget.SAVE_STYLE)) title = "Save";
165+
// style can be a string with multiple comma-separated keywords
166+
// TODO use a utility class for style handling, e.g. StyleUtils.isStyle(style, ...)
167+
if (style == null) title = "Choose a file";
168+
else if (style.toLowerCase().contains(FileWidget.DIRECTORY_STYLE)) title = "Choose a directory";
169+
else if (style.toLowerCase().contains(FileWidget.OPEN_STYLE)) title = "Open";
170+
else if (style.toLowerCase().contains(FileWidget.SAVE_STYLE)) title = "Save";
168171
else title = "Choose a file";
169172

170173
return chooseFile(title, file, style);

0 commit comments

Comments
 (0)