You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@helix.apache.org by "brettkk (JIRA)" <ji...@apache.org> on 2018/04/30 03:43:00 UTC

[jira] [Created] (HELIX-702) Fix Some Potential NPE

brettkk created HELIX-702:
-----------------------------

             Summary: Fix Some Potential NPE
                 Key: HELIX-702
                 URL: https://issues.apache.org/jira/browse/HELIX-702
             Project: Apache Helix
          Issue Type: Bug
            Reporter: brettkk


We have developed a static analysis tool [NPEDetector|https://github.com/lujiefsi/NPEDetector] to find some potential NPE. Our analysis shows that some callees may return null in corner case(e.g. node crash , IO exception), some of their callers have  _!=null_ check but some do not have. In this issue we post a patch which can add  !=null  based on existed !=null  check. For example:

Callee ClusterDataCache#getStateModelDef:

 
{code:java}
public StateModelDefinition getStateModelDef(String stateModelDefRef) {
  if (stateModelDefRef == null) {
    return null;
  }
  return _stateModelDefMap.get(stateModelDefRef);
}
{code}
Caller AutoRebalancer#computeNewIdealState have _!=null_:
{code:java}
StateModelDefinition stateModelDef = clusterData.getStateModelDef(stateModelName);
if (stateModelDef == null) {
  LOG.error("State Model Definition null for resource: " + resourceName);
  throw new HelixException("State Model Definition null for resource: " + resourceName);
}
{code}
but another caller DelayedAutoRebalancer#computeNewIdealState does not have !=null check:
{code:java}
StateModelDefinition stateModelDef =
    clusterData.getStateModelDef(currentIdealState.getStateModelDefRef());
LinkedHashMap<String, Integer> stateCountMap =
    stateModelDef.getStateCountMap(activeNodes.size(), replicaCount);
{code}
So we will add below code in non-(!=null) caller DelayedAutoRebalancer#computeNewIdealState

 
{code:java}
if (stateModelDef == null) {
    throw new HelixException("State Model Definition null for resource:" + resourceName);
}{code}
 

But due to we are not very  familiar with HELIX, hope some expert can review it.

Thanks.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)