HADOOP-11049. javax package system class default is too broad. Contributed by Sangjin Lee

This commit is contained in:
Jason Lowe 2014-09-29 14:36:29 +00:00
parent 9c22065109
commit cf4631d7c9
6 changed files with 98 additions and 17 deletions

View File

@ -885,6 +885,9 @@ Release 2.6.0 - UNRELEASED
HADOOP-11143 NetUtils.wrapException loses inner stack trace on BindException HADOOP-11143 NetUtils.wrapException loses inner stack trace on BindException
(stevel) (stevel)
HADOOP-11049. javax package system class default is too broad (Sangjin Lee
via jlowe)
Release 2.5.1 - 2014-09-05 Release 2.5.1 - 2014-09-05
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -20,12 +20,15 @@ package org.apache.hadoop.util;
import java.io.File; import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Properties;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -45,18 +48,12 @@ public class ApplicationClassLoader extends URLClassLoader {
* classes are considered system classes, and are not loaded by the * classes are considered system classes, and are not loaded by the
* application classloader. * application classloader.
*/ */
public static final String DEFAULT_SYSTEM_CLASSES = public static final String SYSTEM_CLASSES_DEFAULT;
"java.," +
"javax.," + private static final String PROPERTIES_FILE =
"org.w3c.dom.," + "org.apache.hadoop.application-classloader.properties";
"org.xml.sax.," + private static final String SYSTEM_CLASSES_DEFAULT_KEY =
"org.apache.commons.logging.," + "system.classes.default";
"org.apache.log4j.," +
"org.apache.hadoop.," +
"core-default.xml," +
"hdfs-default.xml," +
"mapred-default.xml," +
"yarn-default.xml";
private static final Log LOG = private static final Log LOG =
LogFactory.getLog(ApplicationClassLoader.class.getName()); LogFactory.getLog(ApplicationClassLoader.class.getName());
@ -69,6 +66,30 @@ public class ApplicationClassLoader extends URLClassLoader {
} }
}; };
static {
InputStream is = null;
try {
is = ApplicationClassLoader.class.getClassLoader().
getResourceAsStream(PROPERTIES_FILE);
if (is == null) {
throw new ExceptionInInitializerError("properties file " +
PROPERTIES_FILE + " is not found");
}
Properties props = new Properties();
props.load(is);
// get the system classes default
String systemClassesDefault =
props.getProperty(SYSTEM_CLASSES_DEFAULT_KEY);
if (systemClassesDefault == null) {
throw new ExceptionInInitializerError("property " +
SYSTEM_CLASSES_DEFAULT_KEY + " is not found");
}
SYSTEM_CLASSES_DEFAULT = systemClassesDefault;
} catch (IOException e) {
throw new ExceptionInInitializerError(e);
}
}
private final ClassLoader parent; private final ClassLoader parent;
private final List<String> systemClasses; private final List<String> systemClasses;
@ -85,7 +106,7 @@ public class ApplicationClassLoader extends URLClassLoader {
} }
// if the caller-specified system classes are null or empty, use the default // if the caller-specified system classes are null or empty, use the default
this.systemClasses = (systemClasses == null || systemClasses.isEmpty()) ? this.systemClasses = (systemClasses == null || systemClasses.isEmpty()) ?
Arrays.asList(StringUtils.getTrimmedStrings(DEFAULT_SYSTEM_CLASSES)) : Arrays.asList(StringUtils.getTrimmedStrings(SYSTEM_CLASSES_DEFAULT)) :
systemClasses; systemClasses;
LOG.info("system classes: " + this.systemClasses); LOG.info("system classes: " + this.systemClasses);
} }

View File

@ -0,0 +1,57 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# contains key properties for setting up the application classloader
system.classes.default=java.,\
javax.accessibility.,\
javax.activation.,\
javax.activity.,\
javax.annotation.,\
javax.annotation.processing.,\
javax.crypto.,\
javax.imageio.,\
javax.jws.,\
javax.lang.model.,\
-javax.management.j2ee.,\
javax.management.,\
javax.naming.,\
javax.net.,\
javax.print.,\
javax.rmi.,\
javax.script.,\
-javax.security.auth.message.,\
javax.security.auth.,\
javax.security.cert.,\
javax.security.sasl.,\
javax.sound.,\
javax.sql.,\
javax.swing.,\
javax.tools.,\
javax.transaction.,\
-javax.xml.registry.,\
-javax.xml.rpc.,\
javax.xml.,\
org.w3c.dom.,\
org.xml.sax.,\
org.apache.commons.logging.,\
org.apache.log4j.,\
org.apache.hadoop.,\
core-default.xml,\
hdfs-default.xml,\
mapred-default.xml,\
yarn-default.xml

View File

@ -131,7 +131,7 @@ public class TestRunJar extends TestCase {
String thirdCls = ClassLoaderCheckThird.class.getName(); String thirdCls = ClassLoaderCheckThird.class.getName();
String systemClasses = "-" + mainCls + "," + String systemClasses = "-" + mainCls + "," +
"-" + thirdCls + "," + "-" + thirdCls + "," +
ApplicationClassLoader.DEFAULT_SYSTEM_CLASSES; ApplicationClassLoader.SYSTEM_CLASSES_DEFAULT;
when(runJar.getSystemClasses()).thenReturn(systemClasses); when(runJar.getSystemClasses()).thenReturn(systemClasses);
// create the test jar // create the test jar

View File

@ -498,7 +498,7 @@ public class TestMRApps {
private static final String[] SYS_CLASSES = new String[] { private static final String[] SYS_CLASSES = new String[] {
"/java/fake/Klass", "/java/fake/Klass",
"/javax/fake/Klass", "/javax/management/fake/Klass",
"/org/apache/commons/logging/fake/Klass", "/org/apache/commons/logging/fake/Klass",
"/org/apache/log4j/fake/Klass", "/org/apache/log4j/fake/Klass",
"/org/apache/hadoop/fake/Klass" "/org/apache/hadoop/fake/Klass"
@ -515,7 +515,7 @@ public class TestMRApps {
public void testSystemClasses() { public void testSystemClasses() {
final List<String> systemClasses = final List<String> systemClasses =
Arrays.asList(StringUtils.getTrimmedStrings( Arrays.asList(StringUtils.getTrimmedStrings(
ApplicationClassLoader.DEFAULT_SYSTEM_CLASSES)); ApplicationClassLoader.SYSTEM_CLASSES_DEFAULT));
for (String defaultXml : DEFAULT_XMLS) { for (String defaultXml : DEFAULT_XMLS) {
assertTrue(defaultXml + " must be system resource", assertTrue(defaultXml + " must be system resource",
ApplicationClassLoader.isSystemClass(defaultXml, systemClasses)); ApplicationClassLoader.isSystemClass(defaultXml, systemClasses));

View File

@ -242,7 +242,7 @@ public class TestMRJobs {
// to test AM loading user classes such as output format class, we want // to test AM loading user classes such as output format class, we want
// to blacklist them from the system classes (they need to be prepended // to blacklist them from the system classes (they need to be prepended
// as the first match wins) // as the first match wins)
String systemClasses = ApplicationClassLoader.DEFAULT_SYSTEM_CLASSES; String systemClasses = ApplicationClassLoader.SYSTEM_CLASSES_DEFAULT;
// exclude the custom classes from system classes // exclude the custom classes from system classes
systemClasses = "-" + CustomOutputFormat.class.getName() + ",-" + systemClasses = "-" + CustomOutputFormat.class.getName() + ",-" +
CustomSpeculator.class.getName() + "," + CustomSpeculator.class.getName() + "," +