satybald commented on issue #6724: [FLINK-10380] Add precondition for 
assignToKeyGroup method
URL: https://github.com/apache/flink/pull/6724#issuecomment-427952541
 
 
   @StephanEwen thank you for feedback! From what I see, 
`KeyGroupRangeAssignment#assignToKeyGroup` is utility class. It has 36 usages 
in different classes: state backends, operators, and tests. 
`AbstractKeyedStateBackend#setCurrentKey`, which uses the utilty method has 296 
usages.
   
   I'm bit afraid that catching and testing NPE earlier in the chain requires a 
significant effort to rewrite everything without much benefit. As try/catch 
doesn't make code cleaner and adding the same error message will violate DRY 
principle. 
   
   Also, determine if the key is null earlier in the chain without 
preconditions with try/catch might lead to false positives as there's another 
reason for child method throwing NPE.
   
   From what I see `computeKeyGroupForKeyHash(key.hashCode(), maxParallelism);` 
is the place where key group index calcluated and NPE is thrown in case key is 
null. Would you agree that catching NPE in utility class and overriding with a 
specific message is viable alternative?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to