Skip to content

Commit

Permalink
For Hadoop 1.0.x, make certain constructors public, which were public…
Browse files Browse the repository at this point in the history
… in later versions
  • Loading branch information
srowen committed Nov 1, 2014
1 parent 466e179 commit 0d48f4b
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.spark.mapred

import java.lang.reflect.Modifier

import org.apache.hadoop.mapred.{TaskAttemptID, JobID, JobConf, JobContext, TaskAttemptContext}

private[spark]
Expand All @@ -26,13 +28,22 @@ trait SparkHadoopMapRedUtil {
"org.apache.hadoop.mapred.JobContext")
val ctor = klass.getDeclaredConstructor(classOf[JobConf],
classOf[org.apache.hadoop.mapreduce.JobID])
// In Hadoop 1.0.x, JobContext is an interface, and JobContextImpl is package private.
// Make it accessible if it's not in order to access it.
if (!Modifier.isPublic(ctor.getModifiers)) {
ctor.setAccessible(true)
}
ctor.newInstance(conf, jobId).asInstanceOf[JobContext]
}

def newTaskAttemptContext(conf: JobConf, attemptId: TaskAttemptID): TaskAttemptContext = {
val klass = firstAvailableClass("org.apache.hadoop.mapred.TaskAttemptContextImpl",
"org.apache.hadoop.mapred.TaskAttemptContext")
val ctor = klass.getDeclaredConstructor(classOf[JobConf], classOf[TaskAttemptID])
// See above
if (!Modifier.isPublic(ctor.getModifiers)) {
ctor.setAccessible(true)
}
ctor.newInstance(conf, attemptId).asInstanceOf[TaskAttemptContext]
}

Expand Down

0 comments on commit 0d48f4b

Please sign in to comment.