logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nick Williams (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-230) Preempt StackOverflowEx when both slf4j-impl jar and log4j-to-slf4j jar are on the classpath
Date Wed, 01 May 2013 18:00:20 GMT

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

Nick Williams commented on LOG4J2-230:
--------------------------------------

You're quite welcome. Two points:

1) IIRC, Class.forName ONLY throws ClassNotFoundException. It NEVER throws anything else (well,
technically, any method can throw ThreadDeathException, but one should never stop that from
percolating). I should be double-checked, but I think it's safe to JUST catch CNFE, which
would allow you to get rid of the local variable and throw the ISE from the try block.

2) One could argue that writing a unit test for this is more trouble than it's worth. I personally
disagree with this, because I think the things that are hardest to test are sometimes the
things than need it most, but to each his own. Here is how I would test it. First, I would
write a normal unit test that just called the constructor (this tests the "success condition"
and fails if the constructor throws an exception). Then I would write the "failure condition"
test like so:

A) Use the compiler tools to compile a simple, empty class named org.slf4j.helpers.Log4JLoggerFactory.
Write the resulting class file to %temp%/%unitTestName%/org/slf4j/helpers/Log4JLoggerFactory.class.

B) Instantiate a java.net.URLClassLoader, using the current Thread's context class loader
as the parent loader and passing in a single-element URL array to the %temp%/%unitTestName%/
directory when calling the constructor.

C) Using reflection and the custom class loader, attempt to load and instantiate the SLF4JLoggerContextFactory.
Catch an InvocationTargetException. If the exception is not thrown, fail("Invocation exception
not thrown.") the test. If the exception is thrown, get its cause. The cause should be an
IllegalStateException. If it is some other exception, fail("Wrong exception type ___ thrown.")
the test. Check to make sure the message is the same (just in case). If it's not, fail("Exception
message not correct.") the test.

D) In a finally block, delete the %temp%/%unitTestName% directory.
                
> Preempt StackOverflowEx when both slf4j-impl jar and log4j-to-slf4j jar are on the classpath
> --------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-230
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-230
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: SLF4J Bridge
>    Affects Versions: 2.0-beta5
>            Reporter: Remko Popma
>
> This ticket is to prevent issues like LOG4J2-204.
> Aiming for something similar to what is documented here:
> http://www.slf4j.org/codes.html#jclDelegationLoop

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
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