#62564 - replace Thread.currentThread().getContextClassLoader() with getClass().getClassLoader()

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1836590 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2018-07-24 22:57:18 +00:00
parent 54b8260ccc
commit d3b5a0141e
8 changed files with 10 additions and 10 deletions

View File

@ -324,7 +324,7 @@ public class CryptoFunctions {
}
try {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
ClassLoader cl = CryptoFunctions.class.getClassLoader();
String bcProviderName = "org.bouncycastle.jce.provider.BouncyCastleProvider";
Class<Provider> clazz = (Class<Provider>)cl.loadClass(bcProviderName);
Security.addProvider(clazz.newInstance());

View File

@ -217,7 +217,7 @@ public class EncryptionInfo implements Cloneable {
*/
protected static EncryptionInfoBuilder getBuilder(EncryptionMode encryptionMode)
throws ClassNotFoundException, IllegalAccessException, InstantiationException {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
ClassLoader cl = EncryptionInfo.class.getClassLoader();
EncryptionInfoBuilder eib;
eib = (EncryptionInfoBuilder)cl.loadClass(encryptionMode.builder).newInstance();
return eib;

View File

@ -72,7 +72,7 @@ public class DrawPictureShape extends DrawSimpleShape {
try {
@SuppressWarnings("unchecked")
Class<? extends ImageRenderer> irc = (Class<? extends ImageRenderer>)
Thread.currentThread().getContextClassLoader().loadClass(WMF_IMAGE_RENDERER);
DrawPictureShape.class.getClassLoader().loadClass(WMF_IMAGE_RENDERER);
return irc.newInstance();
} catch (Exception e) {
// WMF image renderer is not on the classpath, continuing with BitmapRenderer

View File

@ -292,7 +292,7 @@ public class SlideShowFactory {
P extends TextParagraph<S,P,? extends TextRun>
> SlideShow<S,P> createSlideShow(String factoryClass, Object args[]) throws IOException, EncryptedDocumentException {
try {
Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(factoryClass);
Class<?> clazz = SlideShowFactory.class.getClassLoader().loadClass(factoryClass);
Class<?> argsClz[] = new Class<?>[args.length];
int i=0;
for (Object o : args) {

View File

@ -294,7 +294,7 @@ public class WorkbookFactory {
private static Workbook createWorkbook(String factoryClass, Object args[]) throws IOException, EncryptedDocumentException {
try {
Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(factoryClass);
Class<?> clazz = WorkbookFactory.class.getClassLoader().loadClass(factoryClass);
Class<?> argsClz[] = new Class<?>[args.length];
int i=0;
for (Object o : args) {

View File

@ -356,8 +356,7 @@ public final class TestPOIXMLDocument {
}
};
Thread thread = Thread.currentThread();
ClassLoader cl = thread.getContextClassLoader();
ClassLoader cl = getClass().getClassLoader();
UncaughtHandler uh = new UncaughtHandler();
// check schema type loading and check if we could run in an OOM

View File

@ -79,8 +79,9 @@ java.net.InetAddress#getCanonicalHostName()
java.net.InetSocketAddress#getHostName() @ Use getHostString() instead, which avoids a DNS lookup
@defaultMessage this method needs special permission
java.lang.Thread#getAllStackTraces()
java.lang.Thread#getAllStackTraces() @ this method needs special permission
java.lang.Thread#getContextClassLoader() @ use getClass().getClassLoader() instead of getContextClassLoader() (see https://stackoverflow.com/a/36228195/2066598)
@defaultMessage Avoid unchecked warnings by using Collections#empty(List|Map|Set) methods
java.util.Collections#EMPTY_LIST

View File

@ -75,7 +75,7 @@ public class HSLFMetroShape<T extends Shape<?,?>> {
}
// org.apache.poi.xslf.usermodel.XSLFMetroShape
ClassLoader cl = Thread.currentThread().getContextClassLoader();
ClassLoader cl = getClass().getClassLoader();
try {
Class<?> ms = cl.loadClass("org.apache.poi.xslf.usermodel.XSLFMetroShape");
Method m = ms.getMethod("parseShape", byte[].class);