Hi,
I have a property that is a Boolean, where null is a distinct and important value ("inherit from parent context").
I currently have code like this
@NonNull
@POST
public ListBoxModel doFillFooItems(@CheckForNull @AncestorInPath Item item) {
if (item != null) {
item.checkPermission(Item.CONFIGURE);
}
final ListBoxModel model = new ListBoxModel();
model.add("description 1", null);
model.add("description 2", "true");
model.add("description 3", "false");
return model;
}
which works exactly as I want it to, setting the Boolean property to null, true or false.
However, this is hitting a SpotBugs check, claiming that the value in that add() call must not be null.
But if I change it to another value, like "", it breaks - that sets the property to false.
So I am wondering how I resolve this - is that value really not supposed to be null (especially given that it works fine)?
If so, that means the code is unsafe and I should not disable the SpotBugs diagnostic (if it would even let me). Is there a way around it? Like can I configure my own string-to-value mapping method for the property (which could map "" to null)?
And if it's not really required to be non-null, should I file a PR to change the annotation for the parameter?
But then that would mean the SpotBugs failure would not go away unless I
set the required Jenkins version to the latest, which isn't exactly
desirable either.
The strange thing is that I don't really remember seeing this issue two years ago when I originally wrote that code.