You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Mridul Muralidharan (JIRA)" <ji...@apache.org> on 2015/07/25 12:51:04 UTC
[jira] [Created] (SPARK-9339) Use of Class.forName(String) should
be replaced with version taking classloader
Mridul Muralidharan created SPARK-9339:
------------------------------------------
Summary: Use of Class.forName(String) should be replaced with version taking classloader
Key: SPARK-9339
URL: https://issues.apache.org/jira/browse/SPARK-9339
Project: Spark
Issue Type: Bug
Reporter: Mridul Muralidharan
In spark, multiple places have ability to take external class as input - example: listener.
Other than in specific cases (like SparkEnv), the code typically calls Class.forName(clazzName)
This works when the class is from within spark - but when the referenced class is from external jar (user provided), it tends to fail.
For example, in 1.3 we get this when using custom listener:
ERROR ApplicationMaster: User class threw exception: Exception when registering SparkListener
org.apache.spark.SparkException: Exception when registering SparkListener
at org.apache.spark.SparkContext.setupAndStartListenerBus(SparkContext.scala:1726)
at org.apache.spark.SparkContext.<init>(SparkContext.scala:429)
at org.apache.spark.SparkContext.<init>(SparkContext.scala:134)
at com.yahoo.corp.yst.webmap.spark.PageRankDataGenerator$.main(PageRankDataGenerator.scala:170)
at com.yahoo.corp.yst.webmap.spark.PageRankDataGenerator.main(PageRankDataGenerator.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.spark.deploy.yarn.ApplicationMaster$$anon$2.run(ApplicationMaster.scala:480)
Caused by: java.lang.ClassNotFoundException: <MySparkListener>
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at org.apache.spark.SparkContext$$anonfun$setupAndStartListenerBus$1.apply(SparkContext.scala:1694)
at org.apache.spark.SparkContext$$anonfun$setupAndStartListenerBus$1.apply(SparkContext.scala:1691)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
at scala.collection.mutable.WrappedArray.foreach(WrappedArray.scala:34)
at org.apache.spark.SparkContext.setupAndStartListenerBus(SparkContext.scala:1691)
... 9 more
Instead of
"val listenerClass = Class.forName(className)" in SparkContext.setupAndStartListenerBus, we should use
"val listenerClass = Class.forName(className, true, Thread.currentThread().getContextClassLoader)"
Note - this is a common pattern in spark, and might be relevant elsewhere too.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org