Details
-
Bug
-
Resolution: Fixed
-
Blocker
-
None
-
None
-
None
Description
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 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());
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.