You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2020/07/20 15:43:02 UTC

[qpid-proton-j] branch master updated: PROTON-2236: restore prior usage of DecodeException and fix up some other cases

This is an automated email from the ASF dual-hosted git repository.

robbie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-proton-j.git


The following commit(s) were added to refs/heads/master by this push:
     new c5d3061  PROTON-2236: restore prior usage of DecodeException and fix up some other cases
c5d3061 is described below

commit c5d306193ba89a07b7070c362d28cc1699c5a8ee
Author: Robbie Gemmell <ro...@apache.org>
AuthorDate: Mon Jul 20 16:38:11 2020 +0100

    PROTON-2236: restore prior usage of DecodeException and fix up some other cases
---
 .../org/apache/qpid/proton/codec/DecoderImpl.java  | 49 +++++++++++-----------
 .../apache/qpid/proton/codec/StringTypeTest.java   |  5 +--
 .../qpid/proton/engine/impl/TransportImplTest.java | 11 +++++
 3 files changed, 37 insertions(+), 28 deletions(-)

diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/DecoderImpl.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/DecoderImpl.java
index a34bd6f..12be526 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/codec/DecoderImpl.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec/DecoderImpl.java
@@ -32,7 +32,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
-import org.apache.qpid.proton.ProtonException;
 import org.apache.qpid.proton.amqp.Binary;
 import org.apache.qpid.proton.amqp.Decimal128;
 import org.apache.qpid.proton.amqp.Decimal32;
@@ -189,7 +188,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultVal;
             default:
-                throw new ProtonException("Expected Boolean type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected Boolean type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -209,7 +208,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultVal;
             default:
-                throw new ProtonException("Expected Boolean type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected Boolean type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -230,7 +229,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultVal;
             default:
-                throw new ProtonException("Expected Byte type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected Byte type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -274,7 +273,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultVal;
             default:
-                throw new ProtonException("Expected Short type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected Short type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -320,7 +319,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultVal;
             default:
-                throw new ProtonException("Expected Integer type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected Integer type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -366,7 +365,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultVal;
             default:
-                throw new ProtonException("Expected Long type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected Long type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -410,7 +409,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultVal;
             default:
-                throw new ProtonException("Expected UnsignedByte type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected UnsignedByte type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -432,7 +431,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultVal;
             default:
-                throw new ProtonException("Expected UnsignedShort type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected UnsignedShort type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -458,7 +457,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultVal;
             default:
-                throw new ProtonException("Expected UnsignedInteger type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected UnsignedInteger type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -484,7 +483,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultVal;
             default:
-                throw new ProtonException("Expected UnsignedLong type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected UnsignedLong type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -506,7 +505,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultVal;
             default:
-                throw new ProtonException("Expected Character type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected Character type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -522,7 +521,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultVal;
             default:
-                throw new ProtonException("Expected Character type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected Character type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -544,7 +543,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultVal;
             default:
-                throw new ProtonException("Expected Float type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected Float type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -588,7 +587,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultVal;
             default:
-                throw new ProtonException("Expected Double type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected Double type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -632,7 +631,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultVal;
             default:
-                throw new ProtonException("Expected UUID type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected UUID type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -654,7 +653,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultValue;
             default:
-                throw new ProtonException("Expected Decimal32 type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected Decimal32 type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -676,7 +675,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultValue;
             default:
-                throw new ProtonException("Expected Decimal64 type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected Decimal64 type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -698,7 +697,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultValue;
             default:
-                throw new ProtonException("Expected Decimal128 type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected Decimal128 type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -720,7 +719,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultValue;
             default:
-                throw new ProtonException("Expected Timestamp type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected Timestamp type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -744,7 +743,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultValue;
             default:
-                throw new ProtonException("Expected Binary type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected Binary type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -768,7 +767,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultValue;
             default:
-                throw new ProtonException("Expected Symbol type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected Symbol type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -792,7 +791,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return defaultValue;
             default:
-                throw new ProtonException("Expected String type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected String type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -813,7 +812,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return null;
             default:
-                throw new ProtonException("Expected List type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected List type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
@@ -838,7 +837,7 @@ public class DecoderImpl implements ByteBufferDecoder
             case EncodingCodes.NULL:
                 return null;
             default:
-                throw new ProtonException("Expected Map type but found encoding: " + EncodingCodes.toString(encodingCode));
+                throw new DecodeException("Expected Map type but found encoding: " + EncodingCodes.toString(encodingCode));
         }
     }
 
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/codec/StringTypeTest.java b/proton-j/src/test/java/org/apache/qpid/proton/codec/StringTypeTest.java
index 5f9415e..3bf3985 100644
--- a/proton-j/src/test/java/org/apache/qpid/proton/codec/StringTypeTest.java
+++ b/proton-j/src/test/java/org/apache/qpid/proton/codec/StringTypeTest.java
@@ -35,7 +35,6 @@ import java.util.List;
 import java.util.Set;
 import java.util.UUID;
 
-import org.apache.qpid.proton.ProtonException;
 import org.apache.qpid.proton.amqp.messaging.AmqpValue;
 import org.junit.Test;
 import org.mockito.Mockito;
@@ -241,7 +240,7 @@ public class StringTypeTest
 
         try {
             decoder.readString();
-        } catch (ProtonException ex) {
+        } catch (DecodeException ex) {
             // Should indicate the type that it found in the error
             assertTrue(ex.getMessage().contains(EncodingCodes.toString(EncodingCodes.UUID)));
         }
@@ -273,7 +272,7 @@ public class StringTypeTest
 
         try {
             decoder.readString();
-        } catch (ProtonException ex) {
+        } catch (DecodeException ex) {
             // Should indicate the type that it found in the error
             assertTrue(ex.getMessage().contains("Unknown-Type:0x01"));
         }
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/TransportImplTest.java b/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/TransportImplTest.java
index 1f89075..5217421 100644
--- a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/TransportImplTest.java
+++ b/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/TransportImplTest.java
@@ -4004,6 +4004,17 @@ public class TransportImplTest
         doInvalidTransferProvokesDecodeErrorTestImpl(bytes, "Unexpected null value - mandatory field not set? (the handle field is mandatory)");
     }
 
+    @Test
+    public void testTransferWithWrongHandleTypeCodeProvokesDecodeError() {
+        // Provide the bytes for Transfer, but give the wrong type code for a not-really-present handle. Provokes a decode error.
+        byte[] bytes = new byte[] {  0x00, 0x00, 0x00, 0x0F, // Frame size = 15 bytes.
+                0x02, 0x00, 0x00, 0x00, // DOFF, TYPE, 2x CHANNEL
+                0x00, 0x53, 0x14, (byte) 0xC0, // Described-type, ulong type, Transfer descriptor, list8.
+                0x03, 0x01, (byte) 0xA3 }; // size (3), count (1), handle (invalid sym8 type constructor given, not really present).
+
+        doInvalidTransferProvokesDecodeErrorTestImpl(bytes, "Expected UnsignedInteger type but found encoding: SYM8:0xa3");
+    }
+
     private void doInvalidTransferProvokesDecodeErrorTestImpl(byte[] bytes, String description) {
         MockTransportImpl transport = new MockTransportImpl();
         Connection connection = Proton.connection();


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org