Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle publication errors properly #314

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion core/src/main/java/org/jboss/logmanager/LoggerNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
import org.wildfly.common.ref.Reaper;
import org.wildfly.common.ref.Reference;

import java.lang.reflect.UndeclaredThrowableException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import java.util.logging.ErrorManager;
import java.util.logging.Filter;
import java.util.logging.Handler;
import java.util.logging.Level;
Expand All @@ -46,6 +50,7 @@ public void reap(Reference<Logger, LoggerNode> reference) {
reference.getAttachment().activeLoggers.remove(reference);
}
};
private static final StackTraceElement[] EMPTY_STACK = new StackTraceElement[0];

/**
* The log context.
Expand Down Expand Up @@ -386,7 +391,26 @@ void publish(final ExtLogRecord record) {
} catch (VirtualMachineError e) {
throw e;
} catch (Throwable t) {
// todo - error handler
ErrorManager errorManager = AccessController.doPrivileged(new PrivilegedAction<ErrorManager>() {
@Override
public ErrorManager run() {
return handler.getErrorManager();
}
});
if (errorManager != null) {
Exception e;
if (t instanceof Exception) {
e = (Exception) t;
} else {
e = new UndeclaredThrowableException(t);
e.setStackTrace(EMPTY_STACK);
}
try {
errorManager.error("Handler publication threw an exception", e, ErrorManager.WRITE_FAILURE);
} catch (Throwable t2) {
StandardOutputStreams.printError(t2, "Handler.reportError caught an exception");
}
}
}
if (useParentHandlers) {
final LoggerNode parent = this.parent;
Expand Down