#fixed code
                              @Override
  public void process(ClusterEvent event) throws Exception {
    long startTime = System.currentTimeMillis();
    LOG.info("START ExternalViewComputeStage.process()");

    HelixManager manager = event.getAttribute(AttributeName.helixmanager.name());
    Map<String, Resource> resourceMap = event.getAttribute(AttributeName.RESOURCES.name());
    ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name());

    if (manager == null || resourceMap == null || cache == null) {
      throw new StageException("Missing attributes in event:" + event
          + ". Requires ClusterManager|RESOURCES|DataCache");
    }

    HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
    PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();

    CurrentStateOutput currentStateOutput =
        event.getAttribute(AttributeName.CURRENT_STATE.name());

    List<ExternalView> newExtViews = new ArrayList<ExternalView>();

    Map<String, ExternalView> curExtViews =
        dataAccessor.getChildValuesMap(keyBuilder.externalViews());

    for (String resourceName : resourceMap.keySet()) {
      ExternalView view = new ExternalView(resourceName);
      // view.setBucketSize(currentStateOutput.getBucketSize(resourceName));
      // if resource ideal state has bucket size, set it
      // otherwise resource has been dropped, use bucket size from current state instead
      Resource resource = resourceMap.get(resourceName);
      if (resource.getBucketSize() > 0) {
        view.setBucketSize(resource.getBucketSize());
      } else {
        view.setBucketSize(currentStateOutput.getBucketSize(resourceName));
      }

      for (Partition partition : resource.getPartitions()) {
        Map<String, String> currentStateMap =
            currentStateOutput.getCurrentStateMap(resourceName, partition);
        if (currentStateMap != null && currentStateMap.size() > 0) {
          // Set<String> disabledInstances
          // = cache.getDisabledInstancesForResource(resource.toString());
          for (String instance : currentStateMap.keySet()) {
            // if (!disabledInstances.contains(instance))
            // {
            view.setState(partition.getPartitionName(), instance, currentStateMap.get(instance));
            // }
          }
        }
      }
      // Update cluster status monitor mbean
      IdealState idealState = cache.getIdealState(resourceName);
      if (!cache.isTaskCache()) {
        ClusterStatusMonitor clusterStatusMonitor =
            event.getAttribute(AttributeName.clusterStatusMonitor.name());
        ResourceConfig resourceConfig = cache.getResourceConfig(resourceName);
        if (idealState != null && (resourceConfig == null || !resourceConfig
            .isMonitoringDisabled())) {
          if (clusterStatusMonitor != null && !idealState.getStateModelDefRef()
              .equalsIgnoreCase(DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE)) {
            StateModelDefinition stateModelDef =
                cache.getStateModelDef(idealState.getStateModelDefRef());
            clusterStatusMonitor
                .setResourceStatus(view, cache.getIdealState(view.getResourceName()),
                    stateModelDef);
          }
        } else {
          // Drop the metrics if the resource is dropped, or the MonitorDisabled is changed to true.
          clusterStatusMonitor.unregisterResource(view.getResourceName());
        }
      }
      ExternalView curExtView = curExtViews.get(resourceName);
      // copy simplefields from IS, in cases where IS is deleted copy it from existing ExternalView
      if (idealState != null) {
        view.getRecord().getSimpleFields().putAll(idealState.getRecord().getSimpleFields());
      } else if (curExtView != null) {
        view.getRecord().getSimpleFields().putAll(curExtView.getRecord().getSimpleFields());
      }

      // compare the new external view with current one, set only on different
      if (curExtView == null || !curExtView.getRecord().equals(view.getRecord())) {
        // Add external view to the list which will be written to ZK later.
        newExtViews.add(view);

        // For SCHEDULER_TASK_RESOURCE resource group (helix task queue), we need to find out which
        // task partitions are finished (COMPLETED or ERROR), update the status update of the original
        // scheduler message, and then remove the partitions from the ideal state
        if (idealState != null
            && idealState.getStateModelDefRef().equalsIgnoreCase(
            DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE)) {
          updateScheduledTaskStatus(view, manager, idealState);
        }
      }
    }
    // TODO: consider not setting the externalview of SCHEDULER_TASK_QUEUE at all.
    // Are there any entity that will be interested in its change?

    // For the resource with DisableExternalView option turned on in IdealState
    // We will not actually create or write the externalView to ZooKeeper.
    List<PropertyKey> keys = new ArrayList<PropertyKey>();
    for(Iterator<ExternalView> it = newExtViews.iterator(); it.hasNext(); ) {
      ExternalView view = it.next();
      String resourceName = view.getResourceName();
      IdealState idealState = cache.getIdealState(resourceName);
      if (idealState != null && idealState.isExternalViewDisabled()) {
        it.remove();
        // remove the external view if the external view exists
        if (curExtViews.containsKey(resourceName)) {
          LOG.info("Remove externalView for resource: " + resourceName);
          dataAccessor.removeProperty(keyBuilder.externalView(resourceName));
        }
      } else {
        keys.add(keyBuilder.externalView(resourceName));
      }
    }

    // add/update external-views
    if (newExtViews.size() > 0) {
      dataAccessor.setChildren(keys, newExtViews);
    }

    // remove dead external-views
    for (String resourceName : curExtViews.keySet()) {
      if (!resourceMap.keySet().contains(resourceName)) {
        LOG.info("Remove externalView for resource: " + resourceName);
        dataAccessor.removeProperty(keyBuilder.externalView(resourceName));
      }
    }

    long endTime = System.currentTimeMillis();
    LOG.info("END " + GenericHelixController.getPipelineType(cache.isTaskCache())
        + " ExternalViewComputeStage.process() for cluster " + cache.getClusterName() + ". took: "
        + (endTime - startTime) + " ms");
  }
#vulnerable code 
                              @Override
  public void process(ClusterEvent event) throws Exception {
    long startTime = System.currentTimeMillis();
    LOG.info("START ExternalViewComputeStage.process()");

    HelixManager manager = event.getAttribute(AttributeName.helixmanager.name());
    Map<String, Resource> resourceMap = event.getAttribute(AttributeName.RESOURCES.name());
    ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name());

    if (manager == null || resourceMap == null || cache == null) {
      throw new StageException("Missing attributes in event:" + event
          + ". Requires ClusterManager|RESOURCES|DataCache");
    }

    HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
    PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();

    CurrentStateOutput currentStateOutput =
        event.getAttribute(AttributeName.CURRENT_STATE.name());

    List<ExternalView> newExtViews = new ArrayList<ExternalView>();

    Map<String, ExternalView> curExtViews =
        dataAccessor.getChildValuesMap(keyBuilder.externalViews());

    for (String resourceName : resourceMap.keySet()) {
      ExternalView view = new ExternalView(resourceName);
      // view.setBucketSize(currentStateOutput.getBucketSize(resourceName));
      // if resource ideal state has bucket size, set it
      // otherwise resource has been dropped, use bucket size from current state instead
      Resource resource = resourceMap.get(resourceName);
      if (resource.getBucketSize() > 0) {
        view.setBucketSize(resource.getBucketSize());
      } else {
        view.setBucketSize(currentStateOutput.getBucketSize(resourceName));
      }

      for (Partition partition : resource.getPartitions()) {
        Map<String, String> currentStateMap =
            currentStateOutput.getCurrentStateMap(resourceName, partition);
        if (currentStateMap != null && currentStateMap.size() > 0) {
          // Set<String> disabledInstances
          // = cache.getDisabledInstancesForResource(resource.toString());
          for (String instance : currentStateMap.keySet()) {
            // if (!disabledInstances.contains(instance))
            // {
            view.setState(partition.getPartitionName(), instance, currentStateMap.get(instance));
            // }
          }
        }
      }
      // Update cluster status monitor mbean
      IdealState idealState = cache.getIdealState(resourceName);
      if (!cache.isTaskCache()) {
        ClusterStatusMonitor clusterStatusMonitor =
            event.getAttribute(AttributeName.clusterStatusMonitor.name());
        ResourceConfig resourceConfig = cache.getResourceConfig(resourceName);
        if (idealState != null && (resourceConfig == null || !resourceConfig
            .isMonitoringDisabled())) {
          if (clusterStatusMonitor != null && !idealState.getStateModelDefRef()
              .equalsIgnoreCase(DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE)) {
            StateModelDefinition stateModelDef =
                cache.getStateModelDef(idealState.getStateModelDefRef());
            clusterStatusMonitor
                .setResourceStatus(view, cache.getIdealState(view.getResourceName()),
                    stateModelDef);
          }
        } else {
          // Drop the metrics if the resource is dropped, or the MonitorDisabled is changed to true.
          clusterStatusMonitor.unregisterResource(view.getResourceName());
        }
      }
      ExternalView curExtView = curExtViews.get(resourceName);
      // copy simplefields from IS, in cases where IS is deleted copy it from existing ExternalView
      if (idealState != null) {
        view.getRecord().getSimpleFields().putAll(idealState.getRecord().getSimpleFields());
      } else if (curExtView != null) {
        view.getRecord().getSimpleFields().putAll(curExtView.getRecord().getSimpleFields());
      }

      // compare the new external view with current one, set only on different
      if (curExtView == null || !curExtView.getRecord().equals(view.getRecord())) {
        // Add external view to the list which will be written to ZK later.
        newExtViews.add(view);

        // For SCHEDULER_TASK_RESOURCE resource group (helix task queue), we need to find out which
        // task partitions are finished (COMPLETED or ERROR), update the status update of the original
        // scheduler message, and then remove the partitions from the ideal state
        if (idealState != null
            && idealState.getStateModelDefRef().equalsIgnoreCase(
            DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE)) {
          updateScheduledTaskStatus(view, manager, idealState);
        }
      }
    }
    // TODO: consider not setting the externalview of SCHEDULER_TASK_QUEUE at all.
    // Are there any entity that will be interested in its change?

    // For the resource with DisableExternalView option turned on in IdealState
    // We will not actually create or write the externalView to ZooKeeper.
    List<PropertyKey> keys = new ArrayList<PropertyKey>();
    for(Iterator<ExternalView> it = newExtViews.iterator(); it.hasNext(); ) {
      ExternalView view = it.next();
      String resourceName = view.getResourceName();
      IdealState idealState = cache.getIdealState(resourceName);
      if (idealState != null && idealState.isExternalViewDisabled()) {
        it.remove();
        // remove the external view if the external view exists
        if (curExtViews.containsKey(resourceName)) {
          LOG.info("Remove externalView for resource: " + resourceName);
          dataAccessor.removeProperty(keyBuilder.externalView(resourceName));
        }
      } else {
        keys.add(keyBuilder.externalView(resourceName));
      }
    }

    // add/update external-views
    if (newExtViews.size() > 0) {
      dataAccessor.setChildren(keys, newExtViews);
    }

    // remove dead external-views
    for (String resourceName : curExtViews.keySet()) {
      if (!resourceMap.keySet().contains(resourceName)) {
        LOG.info("Remove externalView for resource: " + resourceName);
        dataAccessor.removeProperty(keyBuilder.externalView(resourceName));
      }
    }

    long endTime = System.currentTimeMillis();
    LOG.info("END ExternalViewComputeStage.process() for cluster " + cache.getClusterName()
        + ". took: " + (endTime - startTime) + " ms");
  } 
                            #location 35 
                            #vulnerability type NULL_DEREFERENCE