logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Johno Crawford (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (LOG4J2-1642) DefaultShutdownCallbackRegistry throws NoClassDefFoundError
Date Tue, 06 Dec 2016 13:22:58 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-1642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15725355#comment-15725355
] 

Johno Crawford edited comment on LOG4J2-1642 at 12/6/16 1:22 PM:
-----------------------------------------------------------------

The fact LOGGER.error is used in a try catch Throwable inside a shutdown hook is a bad idea,
in my opinion we should consider using System.err or just invoke t.printStacktrace().. instead
as LOGGER.error may fail and the root cause of the error will be masked. I will try patching
log4j-core to find the root cause of my exception.

{code:java}
    /**
     * Executes the registered shutdown callbacks.
     */
    @Override
    public void run() {
        if (state.compareAndSet(State.STARTED, State.STOPPING)) {
            for (final Runnable hook : hooks) {
                System.out.println("Executing shutdown hook " + hook);
                try {
                    hook.run();
                } catch (final Throwable t) {
                    t.printStackTrace();
                    //LOGGER.error(SHUTDOWN_HOOK_MARKER, "Caught exception executing shutdown
hook {}", hook, t);
                }
            }
            state.set(State.STOPPED);
        }
    }
{code}


was (Author: johno):
The fact LOGGER.error is used in a try catch Throwable inside a shutdown hook is a bad idea,
in my opinion we should consider using System.err or just invoke t.printStacktrace().. instead
as LOGGER.error may fail and the root cause of the error will be masked. I will try patching
log4j-core to find the root cause of my exception.

    /**
     * Executes the registered shutdown callbacks.
     */
    @Override
    public void run() {
        if (state.compareAndSet(State.STARTED, State.STOPPING)) {
            for (final Runnable hook : hooks) {
                System.out.println("Executing shutdown hook " + hook);
                try {
                    hook.run();
                } catch (final Throwable t) {
                    t.printStackTrace();
                    //LOGGER.error(SHUTDOWN_HOOK_MARKER, "Caught exception executing shutdown
hook {}", hook, t);
                }
            }
            state.set(State.STOPPED);
        }
    }

> DefaultShutdownCallbackRegistry throws NoClassDefFoundError
> -----------------------------------------------------------
>
>                 Key: LOG4J2-1642
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1642
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.7
>         Environment: java version "1.8.0_60"
> Maven_3.2.2
>            Reporter: Johno Crawford
>
> When running the Maven goals for packaging my project an exception is thrown when the
JVM exits..
> {noformat}
> [INFO] ------------------------------------------------------------------------
> [INFO] BUILD SUCCESS
> [INFO] ------------------------------------------------------------------------
> [INFO] Total time: 01:36 min (Wall Clock)
> [INFO] Finished at: 2016-10-18T12:06:06+03:00
> [INFO] Final Memory: 48M/626M
> [INFO] ------------------------------------------------------------------------
> Exception in thread "pool-1-thread-1" java.lang.NoClassDefFoundError: org/apache/logging/log4j/message/ParameterizedMessage
> 	at org.apache.logging.log4j.message.ParameterizedNoReferenceMessageFactory.newMessage(ParameterizedNoReferenceMessageFactory.java:104)
> 	at org.apache.logging.log4j.message.AbstractMessageFactory.newMessage(AbstractMessageFactory.java:75)
> 	at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2010)
> 	at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1884)
> 	at org.apache.logging.log4j.spi.AbstractLogger.error(AbstractLogger.java:793)
> 	at org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry.run(DefaultShutdownCallbackRegistry.java:76)
> 	at java.lang.Thread.run(Thread.java:745)
> Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.message.ParameterizedMessage
> 	at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
> 	at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
> 	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
> 	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
> 	... 7 more
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message