Skip to content

Commit 6de9072

Browse files
committed
Guard against potential NPE in debug logging mode
The getClientToken (or getClientToAMToken) method in Hadoop apparently returns null sometimes. We need to prevent NPEs that result from this. Yay documentation.
1 parent fabe4c4 commit 6de9072

File tree

2 files changed

+11
-5
lines changed
  • yarn
    • alpha/src/main/scala/org/apache/spark/deploy/yarn
    • stable/src/main/scala/org/apache/spark/deploy/yarn

2 files changed

+11
-5
lines changed

yarn/alpha/src/main/scala/org/apache/spark/deploy/yarn/Client.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,12 @@ private[spark] class Client(
122122
amContainer.setContainerTokens(ByteBuffer.wrap(dob.getData()))
123123
}
124124

125-
/** */
126-
override def getClientToken(report: ApplicationReport): String = report.getClientToken
125+
/**
126+
* Return the security token used by this client to communicate with the ApplicationMaster.
127+
* If no security is enabled, the token returned by the report is null.
128+
*/
129+
override def getClientToken(report: ApplicationReport): String =
130+
Option(report.getClientToken).getOrElse("")
127131
}
128132

129133
private[spark] object Client {

yarn/stable/src/main/scala/org/apache/spark/deploy/yarn/Client.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ private[spark] class Client(
108108
override def getApplicationReport(appId: ApplicationId): ApplicationReport =
109109
yarnClient.getApplicationReport(appId)
110110

111-
/** */
112-
// FIXME: This could throw NPE
111+
/**
112+
* Return the security token used by this client to communicate with the ApplicationMaster.
113+
* If no security is enabled, the token returned by the report is null.
114+
*/
113115
override def getClientToken(report: ApplicationReport): String =
114-
report.getClientToAMToken.toString
116+
Option(report.getClientToAMToken).map(_.toString).getOrElse("")
115117
}
116118

117119
private[spark] object Client {

0 commit comments

Comments
 (0)