Skip to content

Commit 466cd8b

Browse files
wluyimadkayiwa
authored andcommittedMay 31, 2013
OpenMRS crashes irrecoverably if particular errors occur during module loading - TRUNK-2850
(cherry picked from commit 860a84e)
1 parent 9830c6e commit 466cd8b

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed
 

‎web/src/main/java/org/openmrs/web/Listener.java

+24-1
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,12 @@ public static void performWebStartOfModules(ServletContext servletContext) throw
569569
throw ex;
570570
}
571571
catch (Throwable t) {
572-
log.fatal("Unable to refresh the spring application context. Unloading all modules, Error was:", t);
572+
Throwable rootCause = getActualRootCause(t, true);
573+
if (rootCause != null)
574+
log.fatal("Unable to refresh the spring application context. Root Cause was:", rootCause);
575+
else
576+
log.fatal("Unable to refresh the spring application context. Unloading all modules, Error was:", t);
577+
573578
try {
574579
WebModuleUtil.shutdownModules(servletContext);
575580
for (Module mod : ModuleFactory.getLoadedModules()) {// use loadedModules to avoid a concurrentmodificationexception
@@ -608,4 +613,22 @@ public static void performWebStartOfModules(ServletContext servletContext) throw
608613
}
609614
}
610615

616+
/**
617+
* Convenience method that recursively attempts to pull the root case from a Throwable
618+
*
619+
* @param t the Throwable object
620+
* @param isOriginalError specifies if the passed in Throwable is the original Exception that
621+
* was thrown
622+
* @return the root cause if any was found
623+
*/
624+
private static Throwable getActualRootCause(Throwable t, boolean isOriginalError) {
625+
if (t.getCause() != null)
626+
return getActualRootCause(t.getCause(), false);
627+
628+
if (!isOriginalError)
629+
return t;
630+
631+
return null;
632+
}
633+
611634
}

0 commit comments

Comments
 (0)
Please sign in to comment.