qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject [qpid-proton-j] branch master updated: PROTON-2084: add some try-finallys to ensure cleanup
Date Fri, 09 Aug 2019 11:09:59 GMT
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 6dc5587  PROTON-2084: add some try-finallys to ensure cleanup
6dc5587 is described below

commit 6dc5587f1d1b23969a8994f1755198e638e92bc4
Author: Robbie Gemmell <robbie@apache.org>
AuthorDate: Fri Aug 9 11:32:22 2019 +0100

    PROTON-2084: add some try-finallys to ensure cleanup
---
 .../java/org/apache/qpid/proton/codec/MapType.java | 122 +++++++++++----------
 .../FastPathApplicationPropertiesType.java         |   7 +-
 .../messaging/FastPathDeliveryAnnotationsType.java |   7 +-
 .../messaging/FastPathMessageAnnotationsType.java  |   7 +-
 4 files changed, 79 insertions(+), 64 deletions(-)

diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/MapType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/MapType.java
index 40c27b2..78106ce 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/codec/MapType.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec/MapType.java
@@ -82,27 +82,29 @@ public class MapType extends AbstractPrimitiveType<Map>
         // Clear existing fixed key type encoding to prevent application to nested Maps
         setKeyEncoding(null);
 
-        while (iter.hasNext())
-        {
-            final Map.Entry<?, ?> element = iter.next();
-            TypeEncoding elementEncoding;
-
-            if (fixedKeyType == null)
-            {
-                elementEncoding = _encoder.getType(element.getKey()).getEncoding(element.getKey());
-            }
-            else
+        try {
+            while (iter.hasNext())
             {
-                elementEncoding = fixedKeyType.getEncoding(element.getKey());
-            }
+                final Map.Entry<?, ?> element = iter.next();
+                TypeEncoding elementEncoding;
 
-            len += elementEncoding.getConstructorSize() + elementEncoding.getValueSize(element.getKey());
-            elementEncoding = _encoder.getType(element.getValue()).getEncoding(element.getValue());
-            len += elementEncoding.getConstructorSize() + elementEncoding.getValueSize(element.getValue());
-        }
+                if (fixedKeyType == null)
+                {
+                    elementEncoding = _encoder.getType(element.getKey()).getEncoding(element.getKey());
+                }
+                else
+                {
+                    elementEncoding = fixedKeyType.getEncoding(element.getKey());
+                }
 
-        // Reset Existing key type encoding for later encode step or reuse until cleared
by caller
-        setKeyEncoding(fixedKeyType);
+                len += elementEncoding.getConstructorSize() + elementEncoding.getValueSize(element.getKey());
+                elementEncoding = _encoder.getType(element.getValue()).getEncoding(element.getValue());
+                len += elementEncoding.getConstructorSize() + elementEncoding.getValueSize(element.getValue());
+            }
+        } finally {
+            // Reset Existing key type encoding for later encode step or reuse until cleared
by caller
+            setKeyEncoding(fixedKeyType);
+        }
 
         return len;
     }
@@ -175,29 +177,31 @@ public class MapType extends AbstractPrimitiveType<Map>
             // Clear existing fixed key type encoding to prevent application to nested Maps
             setKeyEncoding(null);
 
-            while (iter.hasNext())
-            {
-                final Map.Entry<?, ?> element = iter.next();
-                TypeEncoding elementEncoding;
-
-                if (fixedKeyType == null)
+            try {
+                while (iter.hasNext())
                 {
-                    elementEncoding = _encoder.getType(element.getKey()).getEncoding(element.getKey());
-                }
-                else
-                {
-                    elementEncoding = fixedKeyType.getEncoding(element.getKey());
+                    final Map.Entry<?, ?> element = iter.next();
+                    TypeEncoding elementEncoding;
+
+                    if (fixedKeyType == null)
+                    {
+                        elementEncoding = _encoder.getType(element.getKey()).getEncoding(element.getKey());
+                    }
+                    else
+                    {
+                        elementEncoding = fixedKeyType.getEncoding(element.getKey());
+                    }
+
+                    elementEncoding.writeConstructor();
+                    elementEncoding.writeValue(element.getKey());
+                    elementEncoding = getEncoder().getType(element.getValue()).getEncoding(element.getValue());
+                    elementEncoding.writeConstructor();
+                    elementEncoding.writeValue(element.getValue());
                 }
-
-                elementEncoding.writeConstructor();
-                elementEncoding.writeValue(element.getKey());
-                elementEncoding = getEncoder().getType(element.getValue()).getEncoding(element.getValue());
-                elementEncoding.writeConstructor();
-                elementEncoding.writeValue(element.getValue());
+            } finally {
+                // Reset Existing key type encoding for later encode step or reuse until
cleared by caller
+                setKeyEncoding(fixedKeyType);
             }
-
-            // Reset Existing key type encoding for later encode step or reuse until cleared
by caller
-            setKeyEncoding(fixedKeyType);
         }
 
         @Override
@@ -325,29 +329,31 @@ public class MapType extends AbstractPrimitiveType<Map>
             // Clear existing fixed key type encoding to prevent application to nested Maps
             setKeyEncoding(null);
 
-            while (iter.hasNext())
-            {
-                final Map.Entry<?, ?> element = iter.next();
-                TypeEncoding elementEncoding;
-
-                if (fixedKeyType == null)
+            try {
+                while (iter.hasNext())
                 {
-                    elementEncoding = _encoder.getType(element.getKey()).getEncoding(element.getKey());
+                    final Map.Entry<?, ?> element = iter.next();
+                    TypeEncoding elementEncoding;
+
+                    if (fixedKeyType == null)
+                    {
+                        elementEncoding = _encoder.getType(element.getKey()).getEncoding(element.getKey());
+                    }
+                    else
+                    {
+                        elementEncoding = fixedKeyType.getEncoding(element.getKey());
+                    }
+
+                    elementEncoding.writeConstructor();
+                    elementEncoding.writeValue(element.getKey());
+                    elementEncoding = getEncoder().getType(element.getValue()).getEncoding(element.getValue());
+                    elementEncoding.writeConstructor();
+                    elementEncoding.writeValue(element.getValue());
                 }
-                else
-                {
-                    elementEncoding = fixedKeyType.getEncoding(element.getKey());
-                }
-
-                elementEncoding.writeConstructor();
-                elementEncoding.writeValue(element.getKey());
-                elementEncoding = getEncoder().getType(element.getValue()).getEncoding(element.getValue());
-                elementEncoding.writeConstructor();
-                elementEncoding.writeValue(element.getValue());
+            } finally {
+                // Reset Existing key type encoding for later encode step or reuse until
cleared by caller
+                setKeyEncoding(fixedKeyType);
             }
-
-            // Reset Existing key type encoding for later encode step or reuse until cleared
by caller
-            setKeyEncoding(fixedKeyType);
         }
 
         @Override
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathApplicationPropertiesType.java
b/proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathApplicationPropertiesType.java
index 5ebb9ea..82ed7a2 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathApplicationPropertiesType.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathApplicationPropertiesType.java
@@ -169,8 +169,11 @@ public class FastPathApplicationPropertiesType implements AMQPType<ApplicationPr
         MapType mapType = (MapType) getEncoder().getType(val.getValue());
 
         mapType.setKeyEncoding(stringType);
-        mapType.write(val.getValue());
-        mapType.setKeyEncoding(null);
+        try {
+            mapType.write(val.getValue());
+        } finally {
+            mapType.setKeyEncoding(null);
+        }
     }
 
     public static void register(Decoder decoder, EncoderImpl encoder) {
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathDeliveryAnnotationsType.java
b/proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathDeliveryAnnotationsType.java
index 1bbc321..778f30e 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathDeliveryAnnotationsType.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathDeliveryAnnotationsType.java
@@ -169,8 +169,11 @@ public class FastPathDeliveryAnnotationsType implements AMQPType<DeliveryAnnotat
         MapType mapType = (MapType) getEncoder().getType(val.getValue());
 
         mapType.setKeyEncoding(symbolType);
-        mapType.write(val.getValue());
-        mapType.setKeyEncoding(null);
+        try {
+            mapType.write(val.getValue());
+        } finally {
+            mapType.setKeyEncoding(null);
+        }
     }
 
     public static void register(Decoder decoder, EncoderImpl encoder) {
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathMessageAnnotationsType.java
b/proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathMessageAnnotationsType.java
index 49cc09e..d914833 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathMessageAnnotationsType.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec/messaging/FastPathMessageAnnotationsType.java
@@ -169,8 +169,11 @@ public class FastPathMessageAnnotationsType implements AMQPType<MessageAnnotatio
         MapType mapType = (MapType) getEncoder().getType(val.getValue());
 
         mapType.setKeyEncoding(symbolType);
-        mapType.write(val.getValue());
-        mapType.setKeyEncoding(null);
+        try {
+            mapType.write(val.getValue());
+        } finally {
+            mapType.setKeyEncoding(null);
+        }
     }
 
     public static void register(Decoder decoder, EncoderImpl encoder) {


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


Mime
View raw message