diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java index 3c5762fee..c19ecaa7b 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java @@ -395,8 +395,9 @@ public class InBandBytestreamSession implements BytestreamSession { * @throws IOException if stream is closed and no data should be read anymore */ private void checkClosed() throws IOException { - /* throw no exception if there is data available, but not if close method was invoked */ - if ((isClosed && this.dataQueue.isEmpty()) || closeInvoked) { + // Throw an exception if, and only if, this stream has been already + // closed by the user using the close() method + if (closeInvoked) { // clear data queue in case additional data was received after stream was closed this.dataQueue.clear(); throw new IOException("Stream is closed"); @@ -408,7 +409,7 @@ public class InBandBytestreamSession implements BytestreamSession { } public void close() throws IOException { - if (isClosed) { + if (closeInvoked) { return; } diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java index 968af9338..79b9fc844 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java @@ -609,59 +609,6 @@ public class InBandBytestreamSessionTest { } - /** - * If the session is closed the input stream and output stream should be closed as well. - * - * @throws Exception should not happen - */ - @Test - public void shouldCloseBothStreamsIfSessionIsClosed() throws Exception { - // acknowledgment for data packet - IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID); - protocol.addResponse(resultIQ); - - // acknowledgment for close request - protocol.addResponse(resultIQ, Verification.correspondingSenderReceiver, - Verification.requestTypeSET); - - // get IBB sessions data packet listener - InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream, - initiatorJID); - InputStream inputStream = session.getInputStream(); - PacketListener listener = Whitebox.getInternalState(inputStream, PacketListener.class); - - // build data packet - String base64Data = StringUtils.encodeBase64("Data"); - DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, base64Data); - Data data = new Data(dpe); - - // add data packets - listener.processPacket(data); - - session.close(); - - protocol.verifyAll(); - - try { - while (inputStream.read() != -1) { - } - inputStream.read(); - fail("should throw an exception"); - } - catch (IOException e) { - assertTrue(e.getMessage().contains("closed")); - } - - try { - session.getOutputStream().flush(); - fail("should throw an exception"); - } - catch (IOException e) { - assertTrue(e.getMessage().contains("closed")); - } - - } - /** * If the input stream is closed concurrently there should be no deadlock. *