helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "brettkk (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (HELIX-702) Fix Some Potential NPE
Date Mon, 30 Apr 2018 03:43:00 GMT

     [ https://issues.apache.org/jira/browse/HELIX-702?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

brettkk updated HELIX-702:
--------------------------
    Description: 
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.

  was:
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.


> Fix Some Potential NPE
> ----------------------
>
>                 Key: HELIX-702
>                 URL: https://issues.apache.org/jira/browse/HELIX-702
>             Project: Apache Helix
>          Issue Type: Bug
>            Reporter: brettkk
>            Priority: Major
>
> 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)

Mime
View raw message