[logback-dev] [JIRA] Created: (LBCORE-127) Logback auto config closes the jar file previously opened in user code

tomliliu (JIRA) noreply-jira at qos.ch
Tue Nov 17 05:43:45 CET 2009


Logback auto config closes the jar file previously opened in user code
----------------------------------------------------------------------

                 Key: LBCORE-127
                 URL: http://jira.qos.ch/browse/LBCORE-127
             Project: logback-core
          Issue Type: Bug
          Components: Joran
    Affects Versions: 0.9.17
            Reporter: tomliliu
            Assignee: Logback dev list


User code opens an input stream from a jar file first. Then logback auto config loads the configuration file from the same jar. User code will get the following exception when read the input stream later.

{code title="Stack Trace"}
java.util.zip.ZipException: ZipFile closed
	at java.util.zip.ZipFile.ensureOpenOrZipException(ZipFile.java:413)
	at java.util.zip.ZipFile.access$1100(ZipFile.java:29)
	at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:445)
	at java.io.FilterInputStream.read(FilterInputStream.java:116)
	at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
	at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
	at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
	at java.io.InputStreamReader.read(InputStreamReader.java:167)
	at java.io.BufferedReader.fill(BufferedReader.java:136)
	at java.io.BufferedReader.readLine(BufferedReader.java:299)
	at java.io.BufferedReader.readLine(BufferedReader.java:362)
{code}

{code title="Reproduce"}
InputStream resourceAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(logLocation);
BufferedReader reader = new BufferedReader(new InputStreamReader(resourceAsStream));            
final Logger logger = LoggerFactory.getLogger(LogbackBugReproduce.class);
logger.debug(reader.readLine());
{code}

It looks like in ch.qos.logback.core.joran.GenericConfigurator.doConfigure(URL url) method:
urlConnection.setDefaultUseCaches(false);
InputStream in = urlConnection.getInputStream();
doConfigure(in);
in.close();
The input stream is associated with the same zip file instance of the users. Then close the input stream will close the zip file that user currently is using.

After changing it to:
urlConnection.setUseCaches(false);
InputStream in = urlConnection.getInputStream();
doConfigure(in);
 in.close();
The input stream is associated with a different zip file instance. Then close the input stream will not affect the zip file used by the user code.





-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the logback-dev mailing list