HIVE-29488: KryoException: NullPointerException: Cannot invoke "java.util.Collection.isEmpty()" because "this.delegate" is null#6352
Conversation
| assert (genericUDF != null); | ||
| this.genericUDF = genericUDF; | ||
| this.children = children; | ||
| this.children = children == null ? new ArrayList<>() : new ArrayList<>(children); |
There was a problem hiding this comment.
why you need a new ArrayList<>(children) here? why it can't be just
this.children = children == null ? List.of() : children;
There was a problem hiding this comment.
The new ArrayList<>(children) is required, because otherwise the NPE occurs. I've seen that some callers of getChildren modify the list, e.g., DynamicPartitionPruningOptimization, so I've I opted for new ArrayList<>() instead of List.of().
There was a problem hiding this comment.
@ayushtkn if we don't explicitly convert it to ArrayList, kryo cannot determine the actual runtime List object for ExprNodeGenericFuncDesc.children and uses AbstractMapBasedMultimap$WrappedCollection which is throwing NPE at deserializer in Tez Task.
Explicit cast ensure kryo knows its ArrayList and won't use AbstractMapBasedMultimap$WrappedCollection avoiding this NPE.
There was a problem hiding this comment.
@thomasrebele I suspect its more of Kryo-Guava deseralizer issue when children object is not null. Do you think we need to convert null to empty ?
There was a problem hiding this comment.
It is safer to avoid null for children, as there are several places without null check, e.g., in getExprString. The children are exposed to other classes by getChildren(), so it's simpler to just use an empty list instead of adding null checks everywhere.
…util.Collection.isEmpty()" because "this.delegate" is null Based on a fix by Naresh Panchetty Ramanaiah.
3b152b0 to
513255d
Compare
|
The test TestVectorizationContext had failed, because it changed the children list after creating the ExprNodeGenericFuncDesc. I checked the code, and this modification-after-instantiation seems to be limited to the test class. There are a few candidates that in principle could modify the list, but I don't think that happens in the code:
I therefore propose to change TestVectorizationContext so that it takes into account that ExprNodeGenericFuncDesc makes a copy of the children list. |
|
| assert (genericUDF != null); | ||
| this.genericUDF = genericUDF; | ||
| this.children = children; | ||
| this.children = children == null ? new ArrayList<>() : new ArrayList<>(children); |
There was a problem hiding this comment.
I've seen that some callers of getChildren modify the list, e.g., DynamicPartitionPruningOptimization, so I've I opted for new ArrayList<>() instead of List.of().



See HIVE-29488.
Thank you @nareshpr for providing an initial version of the q file test and a first version of the fix!
What changes were proposed in this pull request?
Put the children of ExprNodeGenericFuncDesc in their own list object.
Why are the changes needed?
Fixes an NPE due to the Kryo library when CBO is disabled.
Does this PR introduce any user-facing change?
No
How was this patch tested?
A q file test was added.