@@ -189,24 +189,22 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
189189 " Specify a vaild path to the correct hive jars using $HIVE_METASTORE_JARS " +
190190 s " or change $HIVE_METASTORE_VERSION to $hiveExecutionVersion. " )
191191 }
192- // We recursively add all jars in the class loader chain,
193- // starting from the given urlClassLoader.
194- def addJars (urlClassLoader : URLClassLoader ): Array [URL ] = {
195- val jarsInParent = urlClassLoader.getParent match {
196- case parent : URLClassLoader => addJars(parent)
197- case other => Array .empty[URL ]
198- }
199192
200- urlClassLoader.getURLs ++ jarsInParent
193+ // We recursively find all jars in the class loader chain,
194+ // starting from the given classLoader.
195+ def allJars (classLoader : ClassLoader ): Array [URL ] = classLoader match {
196+ case null => Array .empty[URL ]
197+ case urlClassLoader : URLClassLoader =>
198+ urlClassLoader.getURLs ++ allJars(urlClassLoader.getParent)
199+ case other => allJars(other.getParent)
201200 }
202201
203- val jars = Utils .getContextOrSparkClassLoader match {
204- case urlClassLoader : URLClassLoader => addJars(urlClassLoader)
205- case other =>
206- throw new IllegalArgumentException (
207- " Unable to locate hive jars to connect to metastore " +
208- s " using classloader ${other.getClass.getName}. " +
209- " Please set spark.sql.hive.metastore.jars" )
202+ val classLoader = Utils .getContextOrSparkClassLoader
203+ val jars = allJars(classLoader)
204+ if (jars.length == 0 ) {
205+ throw new IllegalArgumentException (
206+ " Unable to locate hive jars to connect to metastore. " +
207+ " Please set spark.sql.hive.metastore.jars." )
210208 }
211209
212210 logInfo(
0 commit comments