From 645d2083bf79d334bf3c7fb141526ede33b86c30 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Mon, 22 Dec 2014 12:38:44 +0000 Subject: [PATCH] Bug 56550: Defer the initialization of the _classes to when it is actually needed to allow IBM JDK to at least load the class git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1647302 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/util/OOXMLLite.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/util/OOXMLLite.java b/src/ooxml/java/org/apache/poi/util/OOXMLLite.java index 64920225a..4cbfdbdf3 100644 --- a/src/ooxml/java/org/apache/poi/util/OOXMLLite.java +++ b/src/ooxml/java/org/apache/poi/util/OOXMLLite.java @@ -47,16 +47,7 @@ import org.junit.runner.Result; * @author Yegor Kozlov */ public final class OOXMLLite { - - private static final Field _classes; - static { - try { - _classes = ClassLoader.class.getDeclaredField("classes"); - _classes.setAccessible(true); - } catch (Exception e) { - throw new RuntimeException(e); - } - } + private static Field _classes; /** * Destination directory to copy filtered classes @@ -206,6 +197,16 @@ public final class OOXMLLite { */ @SuppressWarnings("unchecked") private static Map> getLoadedClasses(String ptrn) { + // make the field accessible, we defer this from static initialization to here to + // allow JDKs which do not have this field (e.g. IBM JDK) to at least load the class + // without failing, see https://issues.apache.org/bugzilla/show_bug.cgi?id=56550 + try { + _classes = ClassLoader.class.getDeclaredField("classes"); + _classes.setAccessible(true); + } catch (Exception e) { + throw new RuntimeException(e); + } + ClassLoader appLoader = ClassLoader.getSystemClassLoader(); try { Vector> classes = (Vector>) _classes.get(appLoader);