You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2016/08/19 15:29:53 UTC
svn commit: r1756925 - in
/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima:
InternationalizedException.java internal/util/I18nUtil.java
internal/util/MsgLocalizationClassLoader.java
Author: schor
Date: Fri Aug 19 15:29:53 2016
New Revision: 1756925
URL: http://svn.apache.org/viewvc?rev=1756925&view=rev
Log:
[UIMA-4793][UIMA-3692] capture original thread context class loader and use it as part of the search when looking for resource bundles.
Modified:
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/InternationalizedException.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/I18nUtil.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/MsgLocalizationClassLoader.java
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/InternationalizedException.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/InternationalizedException.java?rev=1756925&r1=1756924&r2=1756925&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/InternationalizedException.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/InternationalizedException.java Fri Aug 19 15:29:53 2016
@@ -72,6 +72,11 @@ public class InternationalizedException
* The exception that caused this exception to occur.
*/
private Throwable mCause;
+
+ /**
+ * the thread local class loader at creation time, see UIMA-4793
+ */
+ final private ClassLoader originalContextClassLoader;
/**
* Creates a new <code>InternationalizedException</code> with a null
@@ -134,6 +139,7 @@ public class InternationalizedException
public InternationalizedException(String aResourceBundleName,
String aMessageKey, Object[] aArguments, Throwable aCause) {
super();
+ originalContextClassLoader = Thread.currentThread().getContextClassLoader();
mCause = aCause;
mResourceBundleName = aResourceBundleName;
mMessageKey = aMessageKey;
@@ -232,8 +238,12 @@ public class InternationalizedException
// check for null message
if (getMessageKey() == null)
return null;
-
- return I18nUtil.localizeMessage(getResourceBundleName(), aLocale, getMessageKey(), getArguments());
+ try {
+ I18nUtil.setTccl(originalContextClassLoader);
+ return I18nUtil.localizeMessage(getResourceBundleName(), aLocale, getMessageKey(), getArguments());
+ } finally {
+ I18nUtil.removeTccl();
+ }
// try {
// // locate the resource bundle for this exception's messages
// // turn over the classloader of the current object explicitly, so that the
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/I18nUtil.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/I18nUtil.java?rev=1756925&r1=1756924&r2=1756925&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/I18nUtil.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/I18nUtil.java Fri Aug 19 15:29:53 2016
@@ -109,19 +109,11 @@ public class I18nUtil {
public static String localizeMessage(String aResourceBundleName, Locale aLocale,
String aMessageKey, Object[] aArguments, ClassLoader aLoader) {
try {
- // if aLoader is null, replace with the I18nUtil.class.getClassLoader()
if (aLoader == null) {
aLoader = MsgLocalizationClassLoader.getMsgLocalizationClassLoader();
-// aLoader = I18nUtil.class.getClassLoader();
-// if (aLoader == null) // bootstrap classLoader; use system classLoader instead
-// {
-// aLoader = ClassLoader.getSystemClassLoader();
-// }
}
-
// locate the resource bundle for this exception's messages
- ResourceBundle bundle = ResourceBundle.getBundle(aResourceBundleName, aLocale, aLoader);
- // retrieve the message from the resource bundle
+ ResourceBundle bundle = ResourceBundle.getBundle(aResourceBundleName, aLocale, aLoader);
String message = bundle.getString(aMessageKey);
// if arguments exist, use MessageFormat to include them
if (aArguments != null && aArguments.length > 0) {
@@ -134,4 +126,13 @@ public class I18nUtil {
return "MESSAGE LOCALIZATION FAILED: " + e.getMessage();
}
}
+
+ public static void setTccl(ClassLoader tccl) {
+ MsgLocalizationClassLoader.CallClimbingClassLoader.originalTccl.set(tccl);
+ }
+
+ public static void removeTccl() {
+ MsgLocalizationClassLoader.CallClimbingClassLoader.originalTccl.remove();
+ }
+
}
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/MsgLocalizationClassLoader.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/MsgLocalizationClassLoader.java?rev=1756925&r1=1756924&r2=1756925&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/MsgLocalizationClassLoader.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/MsgLocalizationClassLoader.java Fri Aug 19 15:29:53 2016
@@ -58,6 +58,7 @@ public class MsgLocalizationClassLoader
static class CallClimbingClassLoader extends ClassLoader {
+ static final ThreadLocal<ClassLoader> originalTccl = new ThreadLocal<>();
/*
* Try to load the class itself before delegate the class loading to its parent
*/
@@ -107,8 +108,15 @@ public class MsgLocalizationClassLoader
// leave c == null
}
}
- // UIMA-3692 try the thread context class loader
+ // UIMA-3692, UIMA-4793 try the thread context class loader
// if not found, will return class not found exception
+ try {
+ ClassLoader cl = originalTccl.get();
+ if (cl != null) {
+ return cl.loadClass(name);
+ }
+ } catch (ClassNotFoundException e) {}
+ // last try: the current thread context class loader
return Thread.currentThread().getContextClassLoader().loadClass(name);
}