Support (un)linkToDeath in Java.

Test: mma, hidl_test_java
Bug: 31632518
Change-Id: Ic324deb5b0b17340328a08e736e07b47a7bea59b
diff --git a/Method.cpp b/Method.cpp
index a085497..e41ebd0 100644
--- a/Method.cpp
+++ b/Method.cpp
@@ -75,7 +75,9 @@
     CHECK(mIsHidlReserved);
     auto it = mCppImpl.find(type);
     if (it != mCppImpl.end()) {
-        it->second(out);
+        if (it->second != nullptr) {
+            it->second(out);
+        }
     }
 }
 
@@ -83,7 +85,9 @@
     CHECK(mIsHidlReserved);
     auto it = mJavaImpl.find(type);
     if (it != mJavaImpl.end()) {
-        it->second(out);
+        if (it->second != nullptr) {
+            it->second(out);
+        }
     }
 }