Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,22 @@ public double readDouble() throws JMSException {
@Override
public String readUTF() throws JMSException {
initializeReading();
final boolean canReset = this.dataIn.markSupported();
if (canReset) {
this.dataIn.mark(Integer.MAX_VALUE);
}
try {
return this.dataIn.readUTF();
} catch (EOFException e) {
throw JmsExceptionSupport.createMessageEOFException(e);
} catch (IOException e) {
if (canReset) {
try {
this.dataIn.reset();
} catch (IOException ignored) {
// if reset fails original failure should be propagated
}
}
throw JmsExceptionSupport.createMessageFormatException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,23 @@ public void testReadUTF() throws JMSException {
assertTrue(msg.readUTF().equals(str));
}

@Test
public void testReadUTFMessageFormatExceptionDoesNotAdvanceReadPointer() throws Exception {
JmsBytesMessage msg = factory.createBytesMessage();
msg.writeShort((short) 2);
msg.writeByte((byte) 0xC0);
msg.writeByte((byte) 0x00);
msg.reset();

assertThrows(MessageFormatException.class, msg::readUTF);

assertEquals(2, msg.readUnsignedShort());
assertEquals((byte) 0xC0, msg.readByte());
assertEquals((byte) 0x00, msg.readByte());

assertThrows(MessageEOFException.class, msg::readByte);
}

@Test
public void testReadBytesbyteArray() throws JMSException {
JmsBytesMessage msg = factory.createBytesMessage();
Expand Down