diff --git a/hertzbeat-collector/hertzbeat-collector-collector/src/main/java/org/apache/hertzbeat/collector/dispatch/CommonDispatcher.java b/hertzbeat-collector/hertzbeat-collector-collector/src/main/java/org/apache/hertzbeat/collector/dispatch/CommonDispatcher.java index 9c36e831a08..f0d6ec2622d 100644 --- a/hertzbeat-collector/hertzbeat-collector-collector/src/main/java/org/apache/hertzbeat/collector/dispatch/CommonDispatcher.java +++ b/hertzbeat-collector/hertzbeat-collector-collector/src/main/java/org/apache/hertzbeat/collector/dispatch/CommonDispatcher.java @@ -183,18 +183,21 @@ public void dispatchMetricsTask(Timeout timeout) { Job job = timerTask.getJob(); job.constructPriorMetrics(); Set metricsSet = job.getNextCollectMetrics(null, true); - metricsSet.forEach(metrics -> { - MetricsCollect metricsCollect = new MetricsCollect(metrics, timeout, this, - collectorIdentity, unitConvertList); - jobRequestQueue.addJob(metricsCollect); - if (metrics.getPrometheus() != null) { - metricsTimeoutMonitorMap.put(String.valueOf(job.getId()), - new MetricsTime(System.currentTimeMillis(), metrics, timeout)); - } else { - metricsTimeoutMonitorMap.put(job.getId() + "-" + metrics.getName(), - new MetricsTime(System.currentTimeMillis(), metrics, timeout)); - } - }); + // Avoid NullPointerException + if (null != metricsSet){ + metricsSet.forEach(metrics -> { + MetricsCollect metricsCollect = new MetricsCollect(metrics, timeout, this, + collectorIdentity, unitConvertList); + jobRequestQueue.addJob(metricsCollect); + if (metrics.getPrometheus() != null) { + metricsTimeoutMonitorMap.put(String.valueOf(job.getId()), + new MetricsTime(System.currentTimeMillis(), metrics, timeout)); + } else { + metricsTimeoutMonitorMap.put(job.getId() + "-" + metrics.getName(), + new MetricsTime(System.currentTimeMillis(), metrics, timeout)); + } + }); + } } @Override