Bug 46539 - The QuietWriter class does not live up to its published contract
The QuietWriter class does not live up to its published contract
Status: RESOLVED FIXED
Product: Log4j
Classification: Unclassified
Component: Other
1.2
Sun Solaris
: P2 major
: ---
Assigned To: log4j-dev
: JDK1.5
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2009-01-15 07:51 UTC by Joseph Greene
Modified: 2009-10-08 21:47 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Greene 2009-01-15 07:51:22 UTC
The QuietWriter class (in org.apache.log4j.helpers) does not live up to its published contract.  The javadocs says that "QuietWriter does not throw exceptions when things go wrong...", however, it will allow Runtime Exceptions to bubble up.

I propose that QuietWriter catch Exception (not just IOException) to fullfil its contract.

This is a real problem running log4j with java 1.5 and the assorted CharsetEncoder state problems.  

java.lang.IllegalStateException: Current state = FLUSHED, new state = CODING
	at java.nio.charset.CharsetEncoder.throwIllegalStateException(CharsetEncoder.java:941)
	at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:537)
	at sun.nio.cs.StreamEncoder$CharsetSE.implWrite(StreamEncoder.java:384)
	at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:136)
	at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:146)
	at java.io.OutputStreamWriter.write(OutputStreamWriter.java:204)
	at java.io.Writer.write(Writer.java:126)
	at org.apache.log4j.helpers.QuietWriter.write(QuietWriter.java:47)
	at org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:301)
	at org.apache.log4j.DailyRollingFileAppender.subAppend(DailyRollingFileAppender.java:358)
	at org.apache.log4j.WriterAppender.append(WriterAppender.java:159)
	at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:230)
	at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:65)
	at org.apache.log4j.AsyncAppender.append(AsyncAppender.java:87)
	at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:230)
	at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:65)
	at org.apache.log4j.Category.callAppenders(Category.java:203)
	at org.apache.log4j.Category.forcedLog(Category.java:388)
	at org.apache.log4j.Category.log(Category.java:853)
	at org.apache.commons.logging.impl.Log4JLogger.warn(Log4JLogger.java:157)

In this example The CharsetEncoder threw an IllegalStateException causing the AsyncAppender's Dispatcher thread to die.  Now the appender is synchronous but another IllegalStateException bubbled out of the application code.
Comment 1 Curt Arnold 2009-10-08 21:47:28 UTC
Committed in revs 823408 and 823409.