[ https://issues.apache.org/jira/browse/JOHNZON-215?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16865538#comment-16865538 ]
Romain Manni-Bucau commented on JOHNZON-215: -------------------------------------------- Hi [~joerg1985], Did you see it mentionned in the spec anywhere? Also, what is the rational behind that behavior which can lead to leaks - this is why it is implemented this way, a lot of people were forgetting to call close and were assuming it was implicit. We can add a property to the jsonreaderfactory to tune it but I have to admit I don't see the use case today, if a concern it is trivial to wrap the input (reader or inputstream) to hold the lock longer than the read time. Hope it makes sense, Romain > JsonReader.readObject() calls Reader.close() > -------------------------------------------- > > Key: JOHNZON-215 > URL: https://issues.apache.org/jira/browse/JOHNZON-215 > Project: Johnzon > Issue Type: Bug > Components: Core > Affects Versions: 1.1.12 > Reporter: Jörg Sautter > Priority: Major > > We try to use the JsonReader to read a Reader based on a channel holding an > exclusive file lock and later on we truncate the channel, write the content > and close the channel / release the lock. > As soon as we call JsonReader.readObject() the reader and the channel is > closed and the file locks are gone. This should - from our point of view - > not happen at this point, only a explicit call to .close() should close the > underlying resources. > This is a code snippet to reproduce the issue: > {{StringReader sr = new StringReader("{}");}} > {{Reader wrapper = new Reader() {}} > {{@Override}} > {{public int read(char[] cbuf, int off, int len) throws IOException{}} > {{return sr.read(cbuf, off, len);}} > {{}}} > {{@Override}} > {{public void close() throws IOException{}} > {{throw new UnsupportedOperationException("someone closed the stream!");}} > {{}}} > {{};}} > {{Json.createReader(wrapper).readObject();}} -- This message was sent by Atlassian JIRA (v7.6.3#76005)