OSDN Git Service

Relax null parameter enforcement for legacy apps
authorChristopher Tate <ctate@google.com>
Wed, 2 Dec 2015 18:54:56 +0000 (10:54 -0800)
committerChristopher Tate <ctate@google.com>
Wed, 2 Dec 2015 19:17:09 +0000 (11:17 -0800)
No longer throws when calling cancel() with a null PendingIntent if
the app targets SDK < NYC.

Bug 25798631

Change-Id: Ic91f42808811645b01802abcc785f4218aac0e8b

core/java/android/app/AlarmManager.java

index bf2e13a..b569416 100644 (file)
@@ -25,7 +25,6 @@ import android.os.Handler;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.os.RemoteException;
-import android.os.SystemClock;
 import android.os.UserHandle;
 import android.os.WorkSource;
 import android.text.TextUtils;
@@ -869,13 +868,19 @@ public class AlarmManager {
      * {@link Intent#filterEquals}), will be canceled.
      *
      * @param operation IntentSender which matches a previously added
-     * IntentSender.
+     * IntentSender. This parameter must not be {@code null}.
      *
      * @see #set
      */
     public void cancel(PendingIntent operation) {
         if (operation == null) {
-            throw new NullPointerException("operation");
+            final String msg = "cancel() called with a null PendingIntent";
+            if (mTargetSdkVersion >= Build.VERSION_CODES.N) {
+                throw new NullPointerException(msg);
+            } else {
+                Log.e(TAG, msg);
+                return;
+            }
         }
 
         try {
@@ -891,7 +896,7 @@ public class AlarmManager {
      */
     public void cancel(OnAlarmListener listener) {
         if (listener == null) {
-            throw new NullPointerException("listener");
+            throw new NullPointerException("cancel() called with a null OnAlarmListener");
         }
 
         ListenerWrapper wrapper = null;