From 998f337a5ea1a8e8b1241aaaadb9e7e8a871be44 Mon Sep 17 00:00:00 2001 From: Siegmar Mantei Date: Tue, 4 Jul 2017 14:24:39 +0200 Subject: [PATCH 1/5] bugfix: catch NullPointerException in onDestroy method. --- src/android/IonicKeyboard.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/android/IonicKeyboard.java b/src/android/IonicKeyboard.java index 9804aa3..e4bd0c3 100644 --- a/src/android/IonicKeyboard.java +++ b/src/android/IonicKeyboard.java @@ -128,7 +128,9 @@ else if ( pixelHeightDiff != previousHeightDiff && ( previousHeightDiff - pixelH @Override public void onDestroy() { - rootView.getViewTreeObserver().removeOnGlobalLayoutListener(list); + if (rootView != null && rootView.getViewTreeObserver() && list != null) { + rootView.getViewTreeObserver().removeOnGlobalLayoutListener(list); + } } } From 39ccea93d8dd5ca4ba58cc3ddfe42d35fce93028 Mon Sep 17 00:00:00 2001 From: Siegmar Mantei Date: Tue, 4 Jul 2017 15:55:37 +0200 Subject: [PATCH 2/5] Bugfix: if expression was wrong add Logging --- src/android/IonicKeyboard.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/android/IonicKeyboard.java b/src/android/IonicKeyboard.java index e4bd0c3..0ea78dd 100644 --- a/src/android/IonicKeyboard.java +++ b/src/android/IonicKeyboard.java @@ -128,9 +128,20 @@ else if ( pixelHeightDiff != previousHeightDiff && ( previousHeightDiff - pixelH @Override public void onDestroy() { - if (rootView != null && rootView.getViewTreeObserver() && list != null) { + if (rootView != null && rootView.getViewTreeObserver() != null && list != null) { rootView.getViewTreeObserver().removeOnGlobalLayoutListener(list); + } else { + String msg = "NullPointerException"; + if (rootView == null) + msg = "rootView variable is null" + else if (rootView.getViewTreeObserver() == null) + msg = "rootView.getViewTreeObserver() is null"; + else if (list == null) + msg = "list variable is null"; + + Log.d("IonicKeyboard", msg); } + super.onDestroy(); } } From a9e417f7b99e3f23a7a72cff7e25c305dcf00a45 Mon Sep 17 00:00:00 2001 From: Siegmar Mantei Date: Tue, 4 Jul 2017 16:52:39 +0200 Subject: [PATCH 3/5] buckfix: add ; --- src/android/IonicKeyboard.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/IonicKeyboard.java b/src/android/IonicKeyboard.java index 0ea78dd..a631cd0 100644 --- a/src/android/IonicKeyboard.java +++ b/src/android/IonicKeyboard.java @@ -133,7 +133,7 @@ public void onDestroy() { } else { String msg = "NullPointerException"; if (rootView == null) - msg = "rootView variable is null" + msg = "rootView variable is null"; else if (rootView.getViewTreeObserver() == null) msg = "rootView.getViewTreeObserver() is null"; else if (list == null) From 63e119a91f3f0a934299beff0e842451e2f580cd Mon Sep 17 00:00:00 2001 From: Siegmar Mantei Date: Wed, 5 Jul 2017 10:23:24 +0200 Subject: [PATCH 4/5] change to try and catch --- src/android/IonicKeyboard.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/android/IonicKeyboard.java b/src/android/IonicKeyboard.java index a631cd0..5118f95 100644 --- a/src/android/IonicKeyboard.java +++ b/src/android/IonicKeyboard.java @@ -1,5 +1,6 @@ package io.ionic.keyboard; +import android.util.Log; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaPlugin; @@ -128,18 +129,19 @@ else if ( pixelHeightDiff != previousHeightDiff && ( previousHeightDiff - pixelH @Override public void onDestroy() { - if (rootView != null && rootView.getViewTreeObserver() != null && list != null) { + String msg = "NullPointerException"; + try { rootView.getViewTreeObserver().removeOnGlobalLayoutListener(list); - } else { - String msg = "NullPointerException"; + } catch (NullPointerException e) { + if (rootView == null) msg = "rootView variable is null"; - else if (rootView.getViewTreeObserver() == null) + if (rootView.getViewTreeObserver() == null) msg = "rootView.getViewTreeObserver() is null"; - else if (list == null) + if (list == null) msg = "list variable is null"; - Log.d("IonicKeyboard", msg); + Log.d("IonicKeyboard", msg, e); } super.onDestroy(); } From c7d5850ba17c5878e200ab07f15a04937dae3c79 Mon Sep 17 00:00:00 2001 From: Siegmar Mantei Date: Wed, 5 Jul 2017 11:03:23 +0200 Subject: [PATCH 5/5] change to general exception catch and beautified code --- src/android/IonicKeyboard.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/android/IonicKeyboard.java b/src/android/IonicKeyboard.java index 5118f95..56ba0da 100644 --- a/src/android/IonicKeyboard.java +++ b/src/android/IonicKeyboard.java @@ -129,19 +129,17 @@ else if ( pixelHeightDiff != previousHeightDiff && ( previousHeightDiff - pixelH @Override public void onDestroy() { - String msg = "NullPointerException"; try { rootView.getViewTreeObserver().removeOnGlobalLayoutListener(list); - } catch (NullPointerException e) { + } catch (Exception e) { + String msg = ""; - if (rootView == null) - msg = "rootView variable is null"; - if (rootView.getViewTreeObserver() == null) - msg = "rootView.getViewTreeObserver() is null"; - if (list == null) - msg = "list variable is null"; + if (rootView == null) msg += "rootView variable is null "; + if (rootView.getViewTreeObserver() == null) msg += "rootView.getViewTreeObserver() is null "; + if (list == null) msg += "list variable is null "; + if (msg.isEmpty()) msg = e.getMessage(); - Log.d("IonicKeyboard", msg, e); + Log.w("IonicKeyboard", msg, e); } super.onDestroy(); }