Uploaded image for project: 'Apache Helix'
  1. Apache Helix
  2. HELIX-702

Fix Some Potential NPE

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      We have developed a static analysis tool 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:

      public StateModelDefinition getStateModelDef(String stateModelDefRef) {
        if (stateModelDefRef == null) {
          return null;
        }
        return _stateModelDefMap.get(stateModelDefRef);
      }
      

      Caller AutoRebalancer#computeNewIdealState have !=null:

      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);
      }
      

      but another caller DelayedAutoRebalancer#computeNewIdealState does not have !=null check:

      StateModelDefinition stateModelDef =
          clusterData.getStateModelDef(currentIdealState.getStateModelDefRef());
      LinkedHashMap<String, Integer> stateCountMap =
          stateModelDef.getStateCountMap(activeNodes.size(), replicaCount);
      

      So we will add below code in non-(!=null) caller DelayedAutoRebalancer#computeNewIdealState

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

       

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

      Thanks.

      Attachments

        Activity

          People

            Unassigned Unassigned
            leigong brettkk
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: