csharp: Raise exception when Array is null.
authorLauro Moura <lauromoura@expertisesolutions.com.br>
Tue, 2 Apr 2019 14:47:36 +0000 (16:47 +0200)
committerWonki Kim <wonki_.kim@samsung.com>
Mon, 8 Apr 2019 01:45:23 +0000 (10:45 +0900)
Reviewers: felipealmeida, vitor.sousa, segfaultxavi

Reviewed By: vitor.sousa

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D8499

src/bindings/mono/eina_mono/eina_array.cs
src/tests/efl_mono/Eina.cs

index f4dd49d69e6c17fa2b3a7c7633b06a68abc47584..b2cdede5659fc551b1f749afd9a4f04e71650dd2 100644 (file)
@@ -99,6 +99,11 @@ public class Array<T> : IEnumerable<T>, IDisposable
 
     public Array(IntPtr handle, bool own)
     {
+        if (handle == IntPtr.Zero)
+        {
+            throw new ArgumentNullException("Handle can't be null");
+        }
+
         Handle = handle;
         Own = own;
         OwnContent = own;
@@ -106,6 +111,11 @@ public class Array<T> : IEnumerable<T>, IDisposable
 
     public Array(IntPtr handle, bool own, bool ownContent)
     {
+        if (handle == IntPtr.Zero)
+        {
+            throw new ArgumentNullException("Handle can't be null");
+        }
+
         Handle = handle;
         Own = own;
         OwnContent = ownContent;
index 8b7f1a96720685c3fe0f21e965882e7910fbfa55..6a07e2f288185e4b892a0bdb7f09eebf23a0ea4f 100644 (file)
@@ -460,6 +460,12 @@ class TestEinaArray
         Test.Assert(a.Handle != IntPtr.Zero);
     }
 
+    public static void create_array_from_null()
+    {
+        Test.AssertRaises<ArgumentNullException>(() => new Eina.Array<int>(IntPtr.Zero, false));
+        Test.AssertRaises<ArgumentNullException>(() => new Eina.Array<int>(IntPtr.Zero, false, false));
+    }
+
     public static void push_int()
     {
         var a = new Eina.Array<int>();