-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Obj#setActiveGroupNames() fails if used on an immutable collection #19
Comments
It does not generally fail on an immutable collection, but only on one that does not permit And... what should happen when someone does call this function with a One can write
or use |
Still worth noting as a bug; it shouldn't have taken me digging through the source code to figure it out. A simple try/catch in the implementation would fix it. |
The documentation of that method says that it will throw a
I'm curious what your suggested "simple" solution would look like. |
Something along these lines? @Override
public void setActiveGroupNames(Collection<? extends String> groupNames)
{
if (groupNames == null)
{
return;
}
if (groupNames.size() == 0)
{
groupNames = Arrays.asList("default");
} else {
boolean containsNull = false
try {
containsNull = groupNames.contains(null)
} catch(NullPointerException e) {}
if (containsNull) {
throw new NullPointerException("The groupNames contains null");
}
}
nextActiveGroupNames =
Collections.unmodifiableSet(new LinkedHashSet<String>(groupNames));
} (I wrote this without an IDE so the syntax may be wrong) |
It was that Just using |
Instead of that
for the check, But I'm still a bit baffled by the NPE that |
The method
Obj#setActiveGroupNames()
fails with aNullPointerException
if used on a collection generated bySet.of()
orList.of()
. This is because those collections throw an exception if you try to test if they containnull
, which you do when in the block:This is pretty annoying because if you're trying to add a face to only one group, that's what you'll be using 90% of the time.
The text was updated successfully, but these errors were encountered: