"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java" between
apache-log4j-2.11.1-src.tar.gz and apache-log4j-2.11.2-src.tar.gz

About: Apache Log4j 2 is a logging library for Java. Source distribution (Java).

Loader.java  (apache-log4j-2.11.1-src):Loader.java  (apache-log4j-2.11.2-src)
skipping to change at line 26 skipping to change at line 26
*/ */
package org.apache.logging.log4j.core.util; package org.apache.logging.log4j.core.util;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.URL; import java.net.URL;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.status.StatusLogger; import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.util.LoaderUtil; import org.apache.logging.log4j.util.LoaderUtil;
import org.apache.logging.log4j.util.PropertiesUtil;
/** /**
* Load resources (or images) from various sources. * Load resources (or images) from various sources.
*/ */
public final class Loader { public final class Loader {
private static final Logger LOGGER = StatusLogger.getLogger(); private static final Logger LOGGER = StatusLogger.getLogger();
private static final String TSTR = "Caught Exception while in Loader.getReso urce. This may be innocuous."; private static final String TSTR = "Caught Exception while in Loader.getReso urce. This may be innocuous.";
skipping to change at line 271 skipping to change at line 272
* Loads and instantiates a Class using the default constructor. * Loads and instantiates a Class using the default constructor.
* *
* @param className The class name. * @param className The class name.
* @return new instance of the class. * @return new instance of the class.
* @throws ClassNotFoundException if the class isn't available to the usual ClassLoaders * @throws ClassNotFoundException if the class isn't available to the usual ClassLoaders
* @throws IllegalAccessException if the class can't be instantiated through a public constructor * @throws IllegalAccessException if the class can't be instantiated through a public constructor
* @throws InstantiationException if there was an exception whilst instantia ting the class * @throws InstantiationException if there was an exception whilst instantia ting the class
* @throws NoSuchMethodException if there isn't a no-args constructor on the class * @throws NoSuchMethodException if there isn't a no-args constructor on the class
* @throws InvocationTargetException if there was an exception whilst constr ucting the class * @throws InvocationTargetException if there was an exception whilst constr ucting the class
*/ */
public static Object newInstanceOf(final String className) @SuppressWarnings("unchecked")
throws ClassNotFoundException, public static <T> T newInstanceOf(final String className)
IllegalAccessException, throws ClassNotFoundException,
InstantiationException, IllegalAccessException,
NoSuchMethodException, InstantiationException,
InvocationTargetException { NoSuchMethodException,
return LoaderUtil.newInstanceOf(className); InvocationTargetException {
final ClassLoader contextClassLoader = Thread.currentThread().getContext
ClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClassLoader());
return LoaderUtil.newInstanceOf(className);
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
} }
/** /**
* Loads, instantiates, and casts a Class using the default constructor. * Loads, instantiates, and casts a Class using the default constructor.
* *
* @param className The class name. * @param className The class name.
* @param clazz The class to cast it to. * @param clazz The class to cast it to.
* @param <T> The type to cast it to. * @param <T> The type to cast it to.
* @return new instance of the class cast to {@code T} * @return new instance of the class cast to {@code T}
* @throws ClassNotFoundException if the class isn't available to the usual ClassLoaders * @throws ClassNotFoundException if the class isn't available to the usual ClassLoaders
* @throws IllegalAccessException if the class can't be instantiated through a public constructor * @throws IllegalAccessException if the class can't be instantiated through a public constructor
* @throws InstantiationException if there was an exception whilst instantia ting the class * @throws InstantiationException if there was an exception whilst instantia ting the class
* @throws NoSuchMethodException if there isn't a no-args constructor on the class * @throws NoSuchMethodException if there isn't a no-args constructor on the class
* @throws InvocationTargetException if there was an exception whilst constr ucting the class * @throws InvocationTargetException if there was an exception whilst constr ucting the class
* @throws ClassCastException if the constructed object isn't type compatibl e with {@code T} * @throws ClassCastException if the constructed object isn't type compatibl e with {@code T}
*/ */
public static <T> T newCheckedInstanceOf(final String className, final Class <T> clazz) public static <T> T newCheckedInstanceOf(final String className, final Class <T> clazz)
throws ClassNotFoundException, throws ClassNotFoundException,
NoSuchMethodException, NoSuchMethodException,
IllegalAccessException, IllegalAccessException,
InvocationTargetException, InvocationTargetException,
InstantiationException { InstantiationException {
return LoaderUtil.newCheckedInstanceOf(className, clazz); final ClassLoader contextClassLoader = Thread.currentThread().getContext
ClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClassLoader());
return LoaderUtil.newCheckedInstanceOf(className, clazz);
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
/**
* Loads and instantiates a class given by a property name.
*
* @param propertyName The property name to look up a class name for.
* @param clazz The class to cast it to.
* @param <T> The type to cast it to.
* @return new instance of the class given in the property or {@code null} i
f the property was unset.
* @throws ClassNotFoundException if the class isn't available to the usu
al ClassLoaders
* @throws IllegalAccessException if the class can't be instantiated thro
ugh a public constructor
* @throws InstantiationException if there was an exception whilst instan
tiating the class
* @throws NoSuchMethodException if there isn't a no-args constructor on
the class
* @throws InvocationTargetException if there was an exception whilst constr
ucting the class
* @throws ClassCastException if the constructed object isn't type co
mpatible with {@code T}
*/
public static <T> T newCheckedInstanceOfProperty(final String propertyName,
final Class<T> clazz)
throws ClassNotFoundException, NoSuchMethodException, InvocationTargetEx
ception, InstantiationException,
IllegalAccessException {
final String className = PropertiesUtil.getProperties().getStringPropert
y(propertyName);
final ClassLoader contextClassLoader = Thread.currentThread().getContext
ClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClassLoader());
return LoaderUtil.newCheckedInstanceOfProperty(propertyName, clazz);
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
} }
/** /**
* Determines if a named Class can be loaded or not. * Determines if a named Class can be loaded or not.
* *
* @param className The class name. * @param className The class name.
* @return {@code true} if the class could be found or {@code false} otherwi se. * @return {@code true} if the class could be found or {@code false} otherwi se.
*/ */
public static boolean isClassAvailable(final String className) { public static boolean isClassAvailable(final String className) {
return LoaderUtil.isClassAvailable(className); final ClassLoader contextClassLoader = Thread.currentThread().getContext
ClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClassLoader());
return LoaderUtil.isClassAvailable(className);
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
} }
public static boolean isJansiAvailable() { public static boolean isJansiAvailable() {
return isClassAvailable("org.fusesource.jansi.AnsiRenderer"); return isClassAvailable("org.fusesource.jansi.AnsiRenderer");
} }
/**
* Loads a class by name. This method respects the {@link #IGNORE_TCCL_PROPE
RTY} Log4j property. If this property is
* specified and set to anything besides {@code false}, then the default Cla
ssLoader will be used.
*
* @param className The class name.
* @return the Class for the given name.
* @throws ClassNotFoundException if the specified class name could not be f
ound
*/
public static Class<?> loadClass(final String className) throws ClassNotFoun
dException {
final ClassLoader contextClassLoader = Thread.currentThread().getContext
ClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClassLoader());
return LoaderUtil.loadClass(className);
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
} }
 End of changes. 5 change blocks. 
14 lines changed or deleted 98 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)