Author: rwesten
Date: Thu Mar 21 15:04:34 2013
New Revision: 1459344
URL: http://svn.apache.org/r1459344
Log:
STANBOL-970: the ContextClassloader is now updated within the doPrivileged block
Modified:
stanbol/trunk/enhancement-engines/tika/src/main/java/org/apache/stanbol/enhancer/engines/tika/TikaEngine.java
Modified:
stanbol/trunk/enhancement-engines/tika/src/main/java/org/apache/stanbol/enhancer/engines/tika/TikaEngine.java
URL:
http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/tika/src/main/java/org/apache/stanbol/enhancer/engines/tika/TikaEngine.java?rev=1459344&r1=1459343&r2=1459344&view=diff
==============================================================================
---
stanbol/trunk/enhancement-engines/tika/src/main/java/org/apache/stanbol/enhancer/engines/tika/TikaEngine.java
(original)
+++
stanbol/trunk/enhancement-engines/tika/src/main/java/org/apache/stanbol/enhancer/engines/tika/TikaEngine.java
Thu Mar 21 15:04:34 2013
@@ -252,26 +252,31 @@ public class TikaEngine
xhtmlHandler = null;
xhtmlSink = null;
}
- /*
- * We need to replace the context Classloader with the Bundle
ClassLoader
- * to ensure that Singleton instances of XML frameworks (such
as node4j)
- * do not leak into the OSGI environment.
- *
- * Most Java XML libs prefer to load implementations by using
the
- * {@link Thread#getContextClassLoader()}. However OSGI has no
control over
- * this {@link ClassLoader}. Because of that there can be
situations where
- * Interfaces are loaded via the Bundle Classloader and the
implementations
- * are taken from the context Classloader. What can cause
- * {@link ClassCastException}, {@link
ExceptionInInitializerError}s, ...
- *
- * Setting the context Classloader to the Bundle classloader
helps to avoid
- * those situations.
- */
- ClassLoader contextClassLoader = updateContextClassLoader();
try {
AccessController.doPrivileged(new
PrivilegedExceptionAction<Object>() {
public Object run() throws IOException, SAXException,
TikaException {
- parser.parse(in, mainHandler, metadata, context);
+ /*
+ * We need to replace the context Classloader with
the Bundle ClassLoader
+ * to ensure that Singleton instances of XML
frameworks (such as node4j)
+ * do not leak into the OSGI environment.
+ *
+ * Most Java XML libs prefer to load
implementations by using the
+ * {@link Thread#getContextClassLoader()}. However
OSGI has no control over
+ * this {@link ClassLoader}. Because of that there
can be situations where
+ * Interfaces are loaded via the Bundle
Classloader and the implementations
+ * are taken from the context Classloader. What
can cause
+ * {@link ClassCastException}, {@link
ExceptionInInitializerError}s, ...
+ *
+ * Setting the context Classloader to the Bundle
classloader helps to avoid
+ * those situations.
+ */
+ ClassLoader contextClassLoader =
updateContextClassLoader();
+ try {
+ parser.parse(in, mainHandler, metadata,
context);
+ }finally {
+ //reset the previous context ClassLoader
+
Thread.currentThread().setContextClassLoader(contextClassLoader);
+ }
return null;
}
});
@@ -284,9 +289,6 @@ public class TikaEngine
} else { //runtime exception
throw RuntimeException.class.cast(e);
}
- } finally {
- //reset the previous context ClassLoader
-
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
} finally { //ensure that the writers are closed correctly
IOUtils.closeQuietly(in);