ice
ice copied to clipboard
Remove Support for Writing `null` Enum Values in Java
The static implementation of ice_write that slice2java generates for enums has a special case to handle null.
If you try to marshal a null enumerator, we'll instead marshal the first declared enumerator.
This seems very unexpected in my opinion.
My only guess is that we're trying to save users from possibly getting a NPE (null-pointer exception).
But... Users really shouldn't be passing null enums around, and we shouldn't be trying to save them from the consequences of doing so.
The code-gen in question:
out << sp << nl << "public static void ice_write(com.zeroc.Ice.OutputStream ostr, " << name << " v)";
out << sb;
out << nl << "if(v == null)";
out << sb;
string firstEnum = enumerators.front()->mappedName();
out << nl << "ostr.writeEnum(" << absolute << '.' << firstEnum << ".value(), " << p->maxValue() << ");";
out << eb;
out << nl << "else";
out << sb;
out << nl << "ostr.writeEnum(v.value(), " << p->maxValue() << ");";
out << eb;
out << eb;
I believe we also have a similar behavior for strings somewhere.