in src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java [1333:1405]
private void handleFlawedHierarchy(final ClassLoader badClassLoader, final Class badClass)
throws LogConfigurationException {
boolean implementsLog = false;
final String logInterfaceName = Log.class.getName();
final Class interfaces[] = badClass.getInterfaces();
for (final Class element : interfaces) {
if (logInterfaceName.equals(element.getName())) {
implementsLog = true;
break;
}
}
if (implementsLog) {
// the class does implement an interface called Log, but
// it is in the wrong classloader
if (isDiagnosticsEnabled()) {
try {
final ClassLoader logInterfaceClassLoader = getClassLoader(Log.class);
logDiagnostic("Class '" + badClass.getName() + "' was found in classloader " +
objectId(badClassLoader) + ". It is bound to a Log interface which is not" +
" the one loaded from classloader " + objectId(logInterfaceClassLoader));
} catch (final Throwable t) {
handleThrowable(t); // may re-throw t
logDiagnostic("Error while trying to output diagnostics about" + " bad class '" + badClass + "'");
}
}
if (!allowFlawedHierarchy) {
final StringBuilder msg = new StringBuilder();
msg.append("Terminating logging for this context ");
msg.append("due to bad log hierarchy. ");
msg.append("You have more than one version of '");
msg.append(Log.class.getName());
msg.append("' visible.");
if (isDiagnosticsEnabled()) {
logDiagnostic(msg.toString());
}
throw new LogConfigurationException(msg.toString());
}
if (isDiagnosticsEnabled()) {
final StringBuilder msg = new StringBuilder();
msg.append("Warning: bad log hierarchy. ");
msg.append("You have more than one version of '");
msg.append(Log.class.getName());
msg.append("' visible.");
logDiagnostic(msg.toString());
}
} else {
// this is just a bad adapter class
if (!allowFlawedDiscovery) {
final StringBuilder msg = new StringBuilder();
msg.append("Terminating logging for this context. ");
msg.append("Log class '");
msg.append(badClass.getName());
msg.append("' does not implement the Log interface.");
if (isDiagnosticsEnabled()) {
logDiagnostic(msg.toString());
}
throw new LogConfigurationException(msg.toString());
}
if (isDiagnosticsEnabled()) {
final StringBuilder msg = new StringBuilder();
msg.append("[WARNING] Log class '");
msg.append(badClass.getName());
msg.append("' does not implement the Log interface.");
logDiagnostic(msg.toString());
}
}
}