Skip to content

Commit 7c6bd0c

Browse files
author
cafreeman
committed
[SPARK-8607] SparkR
Add `getStaticClass` method in SparkR's `RBackendHandler`
1 parent 9379323 commit 7c6bd0c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

core/src/main/scala/org/apache/spark/api/r/RBackendHandler.scala

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ private[r] class RBackendHandler(server: RBackend)
8888
ctx.close()
8989
}
9090

91+
//get classPath for static object. This addresses SPARK-5185
92+
def getStaticClass(objId: String): Class[_] = {
93+
try {
94+
val clsCurrent = Class.forName(objId)
95+
clsCurrent
96+
} catch {
97+
//use contextLoader if we can't find the JAR in the system class loader
98+
case e: ClassNotFoundException =>
99+
val clsContext = Class.forName(objId, true, Thread.currentThread().getContextClassLoader)
100+
clsContext
101+
}
102+
}
103+
91104
def handleMethodCall(
92105
isStatic: Boolean,
93106
objId: String,
@@ -98,7 +111,7 @@ private[r] class RBackendHandler(server: RBackend)
98111
var obj: Object = null
99112
try {
100113
val cls = if (isStatic) {
101-
Class.forName(objId)
114+
getStaticClass(objId)
102115
} else {
103116
JVMObjectTracker.get(objId) match {
104117
case None => throw new IllegalArgumentException("Object not found " + objId)

0 commit comments

Comments
 (0)