Skip to content

Commit

Permalink
Merge pull request #10832 from caskdata/bugfix_release/CDAP-14562-fix…
Browse files Browse the repository at this point in the history
…-classloading-output-issue

CDAP-14562 fixed a classloading issue with output formats
  • Loading branch information
rohitsinha54 authored Nov 9, 2018
2 parents b769094 + 0a21309 commit 1d03226
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import co.cask.cdap.app.metrics.MapReduceMetrics;
import co.cask.cdap.common.conf.ConfigurationUtil;
import co.cask.cdap.common.lang.ClassLoaders;
import co.cask.cdap.common.lang.CombineClassLoader;
import co.cask.cdap.proto.id.EntityId;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
Expand Down Expand Up @@ -193,9 +194,16 @@ private synchronized RecordWriter getRecordWriter(String namedOutput) throws IOE
}

ClassLoader outputFormatClassLoader = outputFormatClass.getClassLoader();
// Use a CombineClassLoader of the output format's classloader and the context classloader
// This is to prevent class not found issues for classes that are visible to the system, but not to the
// program/plugin. More specifically, this happens for XML parsers that are in the Hadoop classpath but usually
// not packaged in programs and plugins.
// see CDAP-14562 for more info
ClassLoader outputClassLoader = new CombineClassLoader(outputFormatClassLoader,
Thread.currentThread().getContextClassLoader());
// This is needed in case the OutputFormat's classloader conflicts with the program classloader (for example,
// TableOutputFormat).
ClassLoader oldClassLoader = ClassLoaders.setContextClassLoader(outputFormatClassLoader);
ClassLoader oldClassLoader = ClassLoaders.setContextClassLoader(outputClassLoader);

try {
// We use ReflectionUtils to instantiate the OutputFormat, because it also calls setConf on the object, if it
Expand Down

0 comments on commit 1d03226

Please sign in to comment.