Skip to content

Commit 7b5e19c

Browse files
author
Mridul Muralidharan
committed
Prevent NPE while running tests
1 parent 39f85e0 commit 7b5e19c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

core/src/main/scala/org/apache/spark/metrics/MetricsSystem.scala

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,19 @@ private[spark] class MetricsSystem private (val instance: String,
129129

130130
sinkConfigs.foreach { kv =>
131131
val classPath = kv._2.getProperty("class")
132-
try {
133-
val sink = Class.forName(classPath)
134-
.getConstructor(classOf[Properties], classOf[MetricRegistry], classOf[SecurityManager])
135-
.newInstance(kv._2, registry, securityMgr)
136-
if (kv._1 == "servlet") {
137-
metricsServlet = Some(sink.asInstanceOf[MetricsServlet])
138-
} else {
139-
sinks += sink.asInstanceOf[Sink]
132+
if (null != classPath) {
133+
try {
134+
val sink = Class.forName(classPath)
135+
.getConstructor(classOf[Properties], classOf[MetricRegistry], classOf[SecurityManager])
136+
.newInstance(kv._2, registry, securityMgr)
137+
if (kv._1 == "servlet") {
138+
metricsServlet = Some(sink.asInstanceOf[MetricsServlet])
139+
} else {
140+
sinks += sink.asInstanceOf[Sink]
141+
}
142+
} catch {
143+
case e: Exception => logError("Sink class " + classPath + " cannot be instantialized", e)
140144
}
141-
} catch {
142-
case e: Exception => logError("Sink class " + classPath + " cannot be instantialized", e)
143145
}
144146
}
145147
}

0 commit comments

Comments
 (0)