From: Mateusz Warowny Date: Fri, 25 Mar 2022 15:59:57 +0000 (+0100) Subject: JAL-3878 Fix NullPointerExceptions caused by nulls in arrays X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=f5b8f799a04ce4fe9fbb8c9486f58ff5676d2c93;p=jalview.git JAL-3878 Fix NullPointerExceptions caused by nulls in arrays --- diff --git a/src/jalview/ws/params/simple/Option.java b/src/jalview/ws/params/simple/Option.java index 78150cd..44f9f5d 100644 --- a/src/jalview/ws/params/simple/Option.java +++ b/src/jalview/ws/params/simple/Option.java @@ -148,9 +148,18 @@ public class Option implements OptionI required = builder.required; defvalue = builder.defaultValue; value = builder.value; - possibleVals = new ArrayList<>(builder.possibleValues); - displayVals = new ArrayList<>( - requireNonNullElse(builder.displayValues, possibleVals)); + if (builder.possibleValues != null) + possibleVals = new ArrayList<>(builder.possibleValues); + if (builder.displayValues != null) + displayVals = new ArrayList<>(builder.displayValues); + else + displayVals = possibleVals; + if (possibleVals == null && displayVals != null) + throw new IllegalArgumentException( + "cannot use displayValues if possibleValues is null"); + if (possibleVals != null && possibleVals.size() != displayVals.size()) + throw new IllegalArgumentException( + "displayValues size does not match possibleValues"); fdetails = builder.detailsUrl; } diff --git a/src/jalview/ws2/client/slivka/SlivkaParamStoreFactory.java b/src/jalview/ws2/client/slivka/SlivkaParamStoreFactory.java index 6ac21df..05e6f0c 100644 --- a/src/jalview/ws2/client/slivka/SlivkaParamStoreFactory.java +++ b/src/jalview/ws2/client/slivka/SlivkaParamStoreFactory.java @@ -96,7 +96,11 @@ class SlivkaParamStoreFactory else if (param instanceof Parameter.ChoiceParameter) { Object ovalue = values.get(param.getId()); - List lvalue = param.isArray() ? (List) ovalue : List.of((String) ovalue); + List lvalue = null; + if (param.isArray()) + lvalue = (List) ovalue; + else if (ovalue != null) + lvalue = List.of((String) ovalue); args.addAll(createChoiceOptions((Parameter.ChoiceParameter) param, lvalue)); } else if (param instanceof Parameter.FileParameter)