File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
main/java/org/apache/qpid/jms/message
test/java/org/apache/qpid/jms/message Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -200,11 +200,22 @@ public double readDouble() throws JMSException {
200200 @ Override
201201 public String readUTF () throws JMSException {
202202 initializeReading ();
203+ final boolean canReset = this .dataIn .markSupported ();
204+ if (canReset ) {
205+ this .dataIn .mark (Integer .MAX_VALUE );
206+ }
203207 try {
204208 return this .dataIn .readUTF ();
205209 } catch (EOFException e ) {
206210 throw JmsExceptionSupport .createMessageEOFException (e );
207211 } catch (IOException e ) {
212+ if (canReset ) {
213+ try {
214+ this .dataIn .reset ();
215+ } catch (IOException ignored ) {
216+ // if reset fails original failure should be propagated
217+ }
218+ }
208219 throw JmsExceptionSupport .createMessageFormatException (e );
209220 }
210221 }
Original file line number Diff line number Diff line change @@ -438,6 +438,23 @@ public void testReadUTF() throws JMSException {
438438 assertTrue (msg .readUTF ().equals (str ));
439439 }
440440
441+ @ Test
442+ public void testReadUTFMessageFormatExceptionDoesNotAdvanceReadPointer () throws Exception {
443+ JmsBytesMessage msg = factory .createBytesMessage ();
444+ msg .writeShort ((short ) 2 );
445+ msg .writeByte ((byte ) 0xC0 );
446+ msg .writeByte ((byte ) 0x00 );
447+ msg .reset ();
448+
449+ assertThrows (MessageFormatException .class , msg ::readUTF );
450+
451+ assertEquals (2 , msg .readUnsignedShort ());
452+ assertEquals ((byte ) 0xC0 , msg .readByte ());
453+ assertEquals ((byte ) 0x00 , msg .readByte ());
454+
455+ assertThrows (MessageEOFException .class , msg ::readByte );
456+ }
457+
441458 @ Test
442459 public void testReadBytesbyteArray () throws JMSException {
443460 JmsBytesMessage msg = factory .createBytesMessage ();
You can’t perform that action at this time.
0 commit comments