[ https://issues.apache.org/jira/browse/QPIDJMS-325?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16173296#comment-16173296 ]
Rob Godfrey edited comment on QPIDJMS-325 at 9/20/17 2:54 PM: -------------------------------------------------------------- [~gemmellr] I don't see anything in the *JavaDoc* that supports reasoning about the behaviour based on how many bytes were originally in the stream. The JavaDoc defines the semantics purely in terms of how many bytes are left in the stream (0) versus the size of the array being read into (hopefully non-zero), and whether a prior read had returned a number of bytes *less* than the number of bytes in the passed array. I agree that if one applies common sense then -1 would seem an entirely reasonable value to return on the first read (no matter the size of the array passed in). But if the JavaDoc provides the only definition of the expected semantics, then I don't think the common sense interpretation can be derived from the JavaDoc (although as I noted in my earlier comment, presuming that the JavaDoc is of sufficient precision and accuracy to be able to define correct semantics is not necessarily a sound course of action :-) ). Edited to add: To be clear I imagine the number of people who really care about this, and the number of applications which will break depending on whether the implementation is changed / remains the same is likely to be 0 (within a small rounding error) was (Author: rgodfrey): [~gemmellr] I don't see anything in the *JavaDoc* that supports reasoning about the behaviour based on how many bytes were originally in the stream. The JavaDoc defines the semantics purely in terms of how many bytes are left in the stream (0) versus the size of the array being read into (hopefully non-zero), and whether a prior read had returned a number of bytes *less* than the number of bytes in the passed array. I agree that if one applies common sense then -1 would seem an entirely reasonable value to return on the first read (no matter the size of the array passed in). But if the JavaDoc provides the only definition of the expected semantics, then I don't think the common sense interpretation can be derived from the JavaDoc (although as I noted in my earlier comment, presuming that the JavaDoc is of sufficient precision and accuracy to be able to define correct semantics is not necessarily a sound course of action :-) ). > reading from empty buffer of a BytesMessage should return 0, not -1 > ------------------------------------------------------------------- > > Key: QPIDJMS-325 > URL: https://issues.apache.org/jira/browse/QPIDJMS-325 > Project: Qpid JMS > Issue Type: Bug > Components: qpid-jms-client > Affects Versions: 0.25.0 > Reporter: Jiri Daněk > Priority: Trivial > > Consider the following test. According to > http://docs.oracle.com/javaee/7/api/javax/jms/BytesMessage.html#readBytes-byte:A- > the #readBytes method should return 0 when it is first called, as the number > of bytes in the buffer is 0 and it read 0 bytes. Only on subsequent calls it > should return -1. What happens now is that the method returns -1 the first > time. > See the commented lines to try the same thing with ActiveMQ JMS Client > library, and with StreamMessage instead of BytesMessage. The behavior there > should be the same. > ActiveMQ passes the test with BytesMessage and fails it with StreamMessage. > Qpid JMS fails with BytesMessage and passes with StreamMessage. > {code} > import org.apache.activemq.ActiveMQConnectionFactory; > import org.apache.qpid.jms.JmsConnectionFactory; > import org.junit.Test; > import javax.jms.*; > import static com.google.common.truth.Truth.assertThat; > public class EmptyBufferInputTest { > @Test > public void testEmptyBufferInput() throws JMSException { > // ConnectionFactory connectionFactory = new > ActiveMQConnectionFactory("tcp://127.0.0.1:61616"); > JmsConnectionFactory connectionFactory = new > JmsConnectionFactory("amqp://127.0.0.1:5672"); > Connection connection = connectionFactory.createConnection(); > Session session = connection.createSession(false, > Session.AUTO_ACKNOWLEDGE); > final byte[] BYTE_LIST = {1, 2, 4}; > // StreamMessage message = session.createStreamMessage(); > BytesMessage message = session.createBytesMessage(); > message.clearBody(); > byte[] readList = new byte[BYTE_LIST.length - 1]; > byte[] emptyList = {}; > message.writeBytes(emptyList); > message.reset(); > final int IS_EMPTY = 0; > assertThat(message.readBytes(readList)).isEqualTo(IS_EMPTY); > } > } > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org For additional commands, e-mail: dev-h...@qpid.apache.org