[MessagePort] Fix Listen Method (#1409)
authorhjhun <36876573+hjhun@users.noreply.github.com>
Fri, 14 Feb 2020 02:32:15 +0000 (11:32 +0900)
committerGitHub <noreply@github.com>
Fri, 14 Feb 2020 02:32:15 +0000 (11:32 +0900)
To avoid throwing an exception in the callback function, this patch adds
an exception handling about Creating Bundle().

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/Tizen.Applications.MessagePort/Tizen.Applications.Messages/MessagePort.cs

index 8b72e57..f7cddc0 100755 (executable)
@@ -33,6 +33,7 @@ namespace Tizen.Applications.Messages
     {
         private static readonly object s_lock = new object();
         private static readonly HashSet<string> s_portMap = new HashSet<string>();
+        private static string LogTag = "MessagePort";
 
         // The name of the local message port
         private readonly string _portName = null;
@@ -156,10 +157,22 @@ namespace Tizen.Applications.Messages
                 }
                 _messageCallBack = (int localPortId, string remoteAppId, string remotePortName, bool trusted, IntPtr message, IntPtr userData) =>
                 {
-                    MessageReceivedEventArgs args = new MessageReceivedEventArgs()
+                    MessageReceivedEventArgs args = new MessageReceivedEventArgs();
+                    try
                     {
-                        Message = new Bundle(new SafeBundleHandle(message, false))
-                    };
+                        args.Message = new Bundle(new SafeBundleHandle(message, false));
+                    }
+                    catch (Exception ex)
+                    {
+                        Log.Error(LogTag, "Exception(" + ex.ToString() + ")");
+                        args.Message = null;
+                    }
+
+                    if (args.Message == null)
+                    {
+                        Log.Error(LogTag, "Failed to create Bundle. message({0})", (message == IntPtr.Zero) ? "null" : message.ToString());
+                        return;
+                    }
 
                     if (!String.IsNullOrEmpty(remotePortName) && !String.IsNullOrEmpty(remoteAppId))
                     {