Code clean up: ILE -> NPE

Bug: 131254583, Bug: 130694010
Test: pass media2-session, media2-player tests, and
      media2-session version-compat-test
Change-Id: I548584902367201c418d35173ad615766631a7e0
diff --git a/media/src/main/java/android/support/v4/media/session/MediaSessionCompat.java b/media/src/main/java/android/support/v4/media/session/MediaSessionCompat.java
index 3409c81..a542406 100644
--- a/media/src/main/java/android/support/v4/media/session/MediaSessionCompat.java
+++ b/media/src/main/java/android/support/v4/media/session/MediaSessionCompat.java
@@ -1956,7 +1956,7 @@
                 MediaDescriptionCompat description,
                 long id) {
             if (description == null) {
-                throw new IllegalArgumentException("Description cannot be null.");
+                throw new IllegalArgumentException("Description cannot be null");
             }
             if (id == UNKNOWN_ID) {
                 throw new IllegalArgumentException("Id cannot be QueueItem.UNKNOWN_ID");
@@ -2227,7 +2227,7 @@
                 PendingIntent mbrIntent, Bundle sessionInfo) {
             if (mbrComponent == null) {
                 throw new IllegalArgumentException(
-                        "MediaButtonReceiver component may not be null.");
+                        "MediaButtonReceiver component may not be null");
             }
             mContext = context;
             mPackageName = context.getPackageName();
diff --git a/media/src/main/java/android/support/v4/media/session/PlaybackStateCompat.java b/media/src/main/java/android/support/v4/media/session/PlaybackStateCompat.java
index 57a3302..d1399d6 100644
--- a/media/src/main/java/android/support/v4/media/session/PlaybackStateCompat.java
+++ b/media/src/main/java/android/support/v4/media/session/PlaybackStateCompat.java
@@ -1054,15 +1054,15 @@
             public Builder(String action, CharSequence name, int icon) {
                 if (TextUtils.isEmpty(action)) {
                     throw new IllegalArgumentException(
-                            "You must specify an action to build a CustomAction.");
+                            "You must specify an action to build a CustomAction");
                 }
                 if (TextUtils.isEmpty(name)) {
                     throw new IllegalArgumentException(
-                            "You must specify a name to build a CustomAction.");
+                            "You must specify a name to build a CustomAction");
                 }
                 if (icon == 0) {
                     throw new IllegalArgumentException(
-                            "You must specify an icon resource id to build a CustomAction.");
+                            "You must specify an icon resource id to build a CustomAction");
                 }
                 mAction = action;
                 mName = name;
@@ -1302,7 +1302,7 @@
         public Builder addCustomAction(PlaybackStateCompat.CustomAction customAction) {
             if (customAction == null) {
                 throw new IllegalArgumentException(
-                        "You may not add a null CustomAction to PlaybackStateCompat.");
+                        "You may not add a null CustomAction to PlaybackStateCompat");
             }
             mCustomActions.add(customAction);
             return this;
diff --git a/media/src/main/java/androidx/media/MediaBrowserServiceCompat.java b/media/src/main/java/androidx/media/MediaBrowserServiceCompat.java
index d9ffcd9..0a12fc9 100644
--- a/media/src/main/java/androidx/media/MediaBrowserServiceCompat.java
+++ b/media/src/main/java/androidx/media/MediaBrowserServiceCompat.java
@@ -953,7 +953,7 @@
                 float value = extras.getFloat(MediaBrowserCompat.EXTRA_DOWNLOAD_PROGRESS);
                 if (value < -EPSILON || value > 1.0f + EPSILON) {
                     throw new IllegalArgumentException("The value of the EXTRA_DOWNLOAD_PROGRESS "
-                            + "field must be a float number within [0.0, 1.0].");
+                            + "field must be a float number within [0.0, 1.0]");
                 }
             }
         }
@@ -1520,10 +1520,10 @@
      */
     public void setSessionToken(MediaSessionCompat.Token token) {
         if (token == null) {
-            throw new IllegalArgumentException("Session token may not be null.");
+            throw new IllegalArgumentException("Session token may not be null");
         }
         if (mSession != null) {
-            throw new IllegalStateException("The session token has already been set.");
+            throw new IllegalStateException("The session token has already been set");
         }
         mSession = token;
         mImpl.setSessionToken(token);
@@ -1950,7 +1950,7 @@
         public BrowserRoot(@NonNull String rootId, @Nullable Bundle extras) {
             if (rootId == null) {
                 throw new IllegalArgumentException("The root id in BrowserRoot cannot be null. " +
-                        "Use null for BrowserRoot instead.");
+                        "Use null for BrowserRoot instead");
             }
             mRootId = rootId;
             mExtras = extras;
diff --git a/media/src/main/java/androidx/media/MediaSessionManager.java b/media/src/main/java/androidx/media/MediaSessionManager.java
index c75c47d..7183e02 100644
--- a/media/src/main/java/androidx/media/MediaSessionManager.java
+++ b/media/src/main/java/androidx/media/MediaSessionManager.java
@@ -50,7 +50,8 @@
      *
      * @return The MediaSessionManager instance for this context.
      */
-    public static @NonNull MediaSessionManager getSessionManager(@NonNull Context context) {
+    @NonNull
+    public static MediaSessionManager getSessionManager(@NonNull Context context) {
         if (context == null) {
             throw new IllegalArgumentException("context cannot be null");
         }
diff --git a/media2/common/src/main/java/androidx/media2/common/MediaMetadata.java b/media2/common/src/main/java/androidx/media2/common/MediaMetadata.java
index 4c1be5b..f3d7a0b 100644
--- a/media2/common/src/main/java/androidx/media2/common/MediaMetadata.java
+++ b/media2/common/src/main/java/androidx/media2/common/MediaMetadata.java
@@ -793,7 +793,7 @@
      */
     public boolean containsKey(@NonNull String key) {
         if (key == null) {
-            throw new IllegalArgumentException("key shouldn't be null");
+            throw new NullPointerException("key shouldn't be null");
         }
         return mBundle.containsKey(key);
     }
@@ -808,7 +808,7 @@
      */
     public @Nullable CharSequence getText(@NonNull @TextKey String key) {
         if (key == null) {
-            throw new IllegalArgumentException("key shouldn't be null");
+            throw new NullPointerException("key shouldn't be null");
         }
         return mBundle.getCharSequence(key);
     }
@@ -836,7 +836,7 @@
      */
     public @Nullable String getString(@NonNull @TextKey String key) {
         if (key == null) {
-            throw new IllegalArgumentException("key shouldn't be null");
+            throw new NullPointerException("key shouldn't be null");
         }
         CharSequence text = mBundle.getCharSequence(key);
         if (text != null) {
@@ -854,7 +854,7 @@
      */
     public long getLong(@NonNull @LongKey String key) {
         if (key == null) {
-            throw new IllegalArgumentException("key shouldn't be null");
+            throw new NullPointerException("key shouldn't be null");
         }
         return mBundle.getLong(key, 0);
     }
@@ -871,7 +871,7 @@
      */
     public @Nullable Rating getRating(@NonNull @RatingKey String key) {
         if (key == null) {
-            throw new IllegalArgumentException("key shouldn't be null");
+            throw new NullPointerException("key shouldn't be null");
         }
         Rating rating = null;
         try {
@@ -892,7 +892,7 @@
      */
     public float getFloat(@NonNull @FloatKey String key) {
         if (key == null) {
-            throw new IllegalArgumentException("key shouldn't be null");
+            throw new NullPointerException("key shouldn't be null");
         }
         return mBundle.getFloat(key);
     }
@@ -906,7 +906,7 @@
      */
     public @Nullable Bitmap getBitmap(@NonNull @BitmapKey String key) {
         if (key == null) {
-            throw new IllegalArgumentException("key shouldn't be null");
+            throw new NullPointerException("key shouldn't be null");
         }
         Bitmap bmp = null;
         try {
@@ -964,7 +964,7 @@
     @RestrictTo(LIBRARY_GROUP_PREFIX)
     public @Nullable Object getObject(@NonNull String key) {
         if (key == null) {
-            throw new IllegalArgumentException("key shouldn't be null");
+            throw new NullPointerException("key shouldn't be null");
         }
         return mBundle.get(key);
     }
@@ -1075,7 +1075,7 @@
         public @NonNull Builder putText(@NonNull @TextKey String key,
                 @Nullable CharSequence value) {
             if (key == null) {
-                throw new IllegalArgumentException("key shouldn't be null");
+                throw new NullPointerException("key shouldn't be null");
             }
             if (METADATA_KEYS_TYPE.containsKey(key)) {
                 if (METADATA_KEYS_TYPE.get(key) != METADATA_TYPE_TEXT) {
@@ -1119,7 +1119,7 @@
         public @NonNull Builder putString(@NonNull @TextKey String key,
                 @Nullable String value) {
             if (key == null) {
-                throw new IllegalArgumentException("key shouldn't be null");
+                throw new NullPointerException("key shouldn't be null");
             }
             if (METADATA_KEYS_TYPE.containsKey(key)) {
                 if (METADATA_KEYS_TYPE.get(key) != METADATA_TYPE_TEXT) {
@@ -1153,7 +1153,7 @@
          */
         public @NonNull Builder putLong(@NonNull @LongKey String key, long value) {
             if (key == null) {
-                throw new IllegalArgumentException("key shouldn't be null");
+                throw new NullPointerException("key shouldn't be null");
             }
             if (METADATA_KEYS_TYPE.containsKey(key)) {
                 if (METADATA_KEYS_TYPE.get(key) != METADATA_TYPE_LONG) {
@@ -1181,7 +1181,7 @@
         public @NonNull Builder putRating(@NonNull @RatingKey String key,
                 @Nullable Rating value) {
             if (key == null) {
-                throw new IllegalArgumentException("key shouldn't be null");
+                throw new NullPointerException("key shouldn't be null");
             }
             if (METADATA_KEYS_TYPE.containsKey(key)) {
                 if (METADATA_KEYS_TYPE.get(key) != METADATA_TYPE_RATING) {
@@ -1213,7 +1213,7 @@
         public @NonNull Builder putBitmap(@NonNull @BitmapKey String key,
                 @Nullable Bitmap value) {
             if (key == null) {
-                throw new IllegalArgumentException("key shouldn't be null");
+                throw new NullPointerException("key shouldn't be null");
             }
             if (METADATA_KEYS_TYPE.containsKey(key)) {
                 if (METADATA_KEYS_TYPE.get(key) != METADATA_TYPE_BITMAP) {
@@ -1234,7 +1234,7 @@
          */
         public @NonNull Builder putFloat(@NonNull @LongKey String key, float value) {
             if (key == null) {
-                throw new IllegalArgumentException("key shouldn't be null");
+                throw new NullPointerException("key shouldn't be null");
             }
             if (METADATA_KEYS_TYPE.containsKey(key)) {
                 if (METADATA_KEYS_TYPE.get(key) != METADATA_TYPE_FLOAT) {
diff --git a/media2/common/src/main/java/androidx/media2/common/ParcelImplListSlice.java b/media2/common/src/main/java/androidx/media2/common/ParcelImplListSlice.java
index 5e96a28..4c858e5 100644
--- a/media2/common/src/main/java/androidx/media2/common/ParcelImplListSlice.java
+++ b/media2/common/src/main/java/androidx/media2/common/ParcelImplListSlice.java
@@ -53,7 +53,7 @@
 
     public ParcelImplListSlice(@NonNull List<ParcelImpl> list) {
         if (list == null) {
-            throw new IllegalArgumentException("list shouldn't be null");
+            throw new NullPointerException("list shouldn't be null");
         }
         mList = list;
     }
diff --git a/media2/common/src/main/java/androidx/media2/common/SessionPlayer.java b/media2/common/src/main/java/androidx/media2/common/SessionPlayer.java
index 13304b4..92a75eb 100644
--- a/media2/common/src/main/java/androidx/media2/common/SessionPlayer.java
+++ b/media2/common/src/main/java/androidx/media2/common/SessionPlayer.java
@@ -756,10 +756,10 @@
             @NonNull /*@CallbackExecutor*/ Executor executor,
             @NonNull PlayerCallback callback) {
         if (executor == null) {
-            throw new IllegalArgumentException("executor shouldn't be null");
+            throw new NullPointerException("executor shouldn't be null");
         }
         if (callback == null) {
-            throw new IllegalArgumentException("callback shouldn't be null");
+            throw new NullPointerException("callback shouldn't be null");
         }
 
         synchronized (mLock) {
@@ -781,7 +781,7 @@
      */
     public final void unregisterPlayerCallback(@NonNull PlayerCallback callback) {
         if (callback == null) {
-            throw new IllegalArgumentException("callback shouldn't be null");
+            throw new NullPointerException("callback shouldn't be null");
         }
         synchronized (mLock) {
             for (int i = mCallbacks.size() - 1; i >= 0; i--) {
diff --git a/media2/common/src/main/java/androidx/media2/common/UriMediaItem.java b/media2/common/src/main/java/androidx/media2/common/UriMediaItem.java
index 0b772fb..ebaca47 100644
--- a/media2/common/src/main/java/androidx/media2/common/UriMediaItem.java
+++ b/media2/common/src/main/java/androidx/media2/common/UriMediaItem.java
@@ -147,7 +147,7 @@
                 if (cookieHandler != null && !(cookieHandler instanceof CookieManager)) {
                     throw new IllegalArgumentException(
                             "The cookie handler has to be of CookieManager type "
-                                    + "when cookies are provided.");
+                                    + "when cookies are provided");
                 }
             }
 
diff --git a/media2/player/api/1.0.0-alpha05.txt b/media2/player/api/1.0.0-alpha05.txt
index e4e13a5..85b0b16 100644
--- a/media2/player/api/1.0.0-alpha05.txt
+++ b/media2/player/api/1.0.0-alpha05.txt
@@ -5,7 +5,7 @@
     ctor public MediaPlayer(android.content.Context);
     method public com.google.common.util.concurrent.ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> addPlaylistItem(int, androidx.media2.common.MediaItem);
     method public com.google.common.util.concurrent.ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> attachAuxEffect(int);
-    method public void close() throws java.lang.Exception;
+    method public void close();
     method public androidx.media.AudioAttributesCompat? getAudioAttributes();
     method public int getAudioSessionId();
     method public long getBufferedPosition();
diff --git a/media2/player/api/current.txt b/media2/player/api/current.txt
index e4e13a5..85b0b16 100644
--- a/media2/player/api/current.txt
+++ b/media2/player/api/current.txt
@@ -5,7 +5,7 @@
     ctor public MediaPlayer(android.content.Context);
     method public com.google.common.util.concurrent.ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> addPlaylistItem(int, androidx.media2.common.MediaItem);
     method public com.google.common.util.concurrent.ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> attachAuxEffect(int);
-    method public void close() throws java.lang.Exception;
+    method public void close();
     method public androidx.media.AudioAttributesCompat? getAudioAttributes();
     method public int getAudioSessionId();
     method public long getBufferedPosition();
diff --git a/media2/player/src/androidTest/java/androidx/media2/player/MediaPlayerDrmTest.java b/media2/player/src/androidTest/java/androidx/media2/player/MediaPlayerDrmTest.java
index 48a04b9..71a18e7 100644
--- a/media2/player/src/androidTest/java/androidx/media2/player/MediaPlayerDrmTest.java
+++ b/media2/player/src/androidTest/java/androidx/media2/player/MediaPlayerDrmTest.java
@@ -1081,7 +1081,7 @@
                 throw new InterruptedException(
                         "Timeout waiting for IDs " + Arrays.toString(waitForIds)
                         + "; received " + mCompleteIds.toString()
-                        + ".  Make sure you have WiFi or some other connectivity for this test.");
+                        + ".  Make sure you have WiFi or some other connectivity for this test");
             }
         }
 
diff --git a/media2/player/src/androidTest/java/androidx/media2/player/MediaPlayer_AudioFocusTest.java b/media2/player/src/androidTest/java/androidx/media2/player/MediaPlayer_AudioFocusTest.java
index b0d64fc..2ac9569 100644
--- a/media2/player/src/androidTest/java/androidx/media2/player/MediaPlayer_AudioFocusTest.java
+++ b/media2/player/src/androidTest/java/androidx/media2/player/MediaPlayer_AudioFocusTest.java
@@ -380,19 +380,6 @@
     }
 
     @Test
-    public void testAudioFocus_setVolumeZeroWhenAudioAttributesIsMissing()
-            throws Exception {
-        prepareLooper();
-
-        // Request an audio focus in advance.
-        requestAudioFocus(AUDIOFOCUS_GAIN);
-        initPlayer(null);
-        mPlayer.play();
-        assertNoAudioFocusChanges(AUDIOFOCUS_GAIN);
-        assertEquals(0, mPlayer.getPlayerVolume(), 0.1f);
-    }
-
-    @Test
     public void testAudioFocus_pauseForFocusLoss() throws Exception {
         prepareLooper();
 
diff --git a/media2/player/src/main/java/androidx/media2/player/MediaPlayer.java b/media2/player/src/main/java/androidx/media2/player/MediaPlayer.java
index e17f349..b4fd33c 100644
--- a/media2/player/src/main/java/androidx/media2/player/MediaPlayer.java
+++ b/media2/player/src/main/java/androidx/media2/player/MediaPlayer.java
@@ -677,6 +677,9 @@
      * @param context A {@link Context} that will be used to resolve {@link UriMediaItem}.
      */
     public MediaPlayer(@NonNull Context context) {
+        if (context == null) {
+            throw new NullPointerException("context shouldn't be null");
+        }
         mState = PLAYER_STATE_IDLE;
         mPlayer = MediaPlayer2.create(context);
         mExecutor = Executors.newFixedThreadPool(1);
@@ -851,6 +854,9 @@
     @Override
     public ListenableFuture<PlayerResult> setAudioAttributes(
             @NonNull final AudioAttributesCompat attr) {
+        if (attr == null) {
+            throw new NullPointerException("attr shouldn't be null");
+        }
         PendingFuture<PlayerResult> pendingFuture = new PendingFuture<PlayerResult>(mExecutor) {
             @Override
             List<ResolvableFuture<PlayerResult>> onExecute() {
@@ -1486,7 +1492,7 @@
     }
 
     @Override
-    public void close() throws Exception {
+    public void close() {
         reset();
         mAudioFocusHandler.close();
         mPlayer.close();
@@ -1674,6 +1680,9 @@
      */
     @NonNull
     public ListenableFuture<PlayerResult> setPlaybackParams(@NonNull final PlaybackParams params) {
+        if (params == null) {
+            throw new NullPointerException("params shouldn't be null");
+        }
         PendingFuture<PlayerResult> pendingFuture = new PendingFuture<PlayerResult>(mExecutor) {
             @Override
             List<ResolvableFuture<PlayerResult>> onExecute() {
@@ -1973,6 +1982,9 @@
     // TODO: support subtitle track selection  (b/130312596)
     @NonNull
     public ListenableFuture<PlayerResult> selectTrack(@NonNull final TrackInfo trackInfo) {
+        if (trackInfo == null) {
+            throw new NullPointerException("trackInfo shouldn't be null");
+        }
         final int trackId = trackInfo.mId;
         PendingFuture<PlayerResult> pendingFuture = new PendingFuture<PlayerResult>(mExecutor) {
             @Override
@@ -2014,6 +2026,9 @@
     @RestrictTo(LIBRARY_GROUP_PREFIX)
     @NonNull
     public ListenableFuture<PlayerResult> deselectTrack(@NonNull final TrackInfo trackInfo) {
+        if (trackInfo == null) {
+            throw new NullPointerException("trackInfo shouldn't be null");
+        }
         final int trackId = trackInfo.mId;
         PendingFuture<PlayerResult> pendingFuture = new PendingFuture<PlayerResult>(mExecutor) {
             @Override
@@ -2053,6 +2068,9 @@
      * @throws IllegalArgumentException if the callback is {@code null}.
      */
     public void unregisterPlayerCallback(@NonNull PlayerCallback callback) {
+        if (callback == null) {
+            throw new NullPointerException("callback shouldn't be null");
+        }
         super.unregisterPlayerCallback(callback);
     }
 
@@ -2097,6 +2115,9 @@
     // This is an asynchronous call.
     @NonNull
     public ListenableFuture<DrmResult> prepareDrm(@NonNull final UUID uuid) {
+        if (uuid == null) {
+            throw new NullPointerException("uuid shouldn't be null");
+        }
         PendingFuture<DrmResult> pendingFuture = new PendingFuture<DrmResult>(mExecutor) {
             @Override
             List<ResolvableFuture<DrmResult>> onExecute() {
@@ -2229,6 +2250,9 @@
      */
     @RestrictTo(LIBRARY_GROUP_PREFIX)
     public void restoreDrmKeys(@NonNull byte[] keySetId) throws NoDrmSchemeException {
+        if (keySetId == null) {
+            throw new NullPointerException("keySetId shouldn't be null");
+        }
         try {
             mPlayer.restoreDrmKeys(keySetId);
         } catch (MediaPlayer2.NoDrmSchemeException e) {
@@ -2249,6 +2273,9 @@
     @RestrictTo(LIBRARY_GROUP_PREFIX)
     @NonNull
     public String getDrmPropertyString(@NonNull String propertyName) throws NoDrmSchemeException {
+        if (propertyName == null) {
+            throw new NullPointerException("propertyName shouldn't be null");
+        }
         try {
             return mPlayer.getDrmPropertyString(propertyName);
         } catch (MediaPlayer2.NoDrmSchemeException e) {
@@ -2270,6 +2297,12 @@
     @RestrictTo(LIBRARY_GROUP_PREFIX)
     public void setDrmPropertyString(@NonNull String propertyName, @NonNull String value)
             throws NoDrmSchemeException {
+        if (propertyName == null) {
+            throw new NullPointerException("propertyName shouldn't be null");
+        }
+        if (value == null) {
+            throw new NullPointerException("value shouldn't be null");
+        }
         try {
             mPlayer.setDrmPropertyString(propertyName, value);
         } catch (MediaPlayer2.NoDrmSchemeException e) {
@@ -2374,6 +2407,9 @@
     @SuppressWarnings("WeakerAccess") /* synthetic access */
     List<ResolvableFuture<PlayerResult>> setMediaItemsInternal(
             @NonNull MediaItem curItem, @Nullable MediaItem nextItem) {
+        if (curItem == null) {
+            throw new NullPointerException("curItem shouldn't be null");
+        }
         boolean setMediaItemCalled;
         synchronized (mPlaylistLock) {
             setMediaItemCalled = mSetMediaItemCalled;
diff --git a/media2/player/src/main/java/androidx/media2/player/MediaPlayer2Impl.java b/media2/player/src/main/java/androidx/media2/player/MediaPlayer2Impl.java
index 35ba3e5..bf1a24b 100644
--- a/media2/player/src/main/java/androidx/media2/player/MediaPlayer2Impl.java
+++ b/media2/player/src/main/java/androidx/media2/player/MediaPlayer2Impl.java
@@ -358,7 +358,7 @@
             @Override
             void process() {
                 if (items == null || items.size() == 0) {
-                    throw new IllegalArgumentException("media item list cannot be null or empty.");
+                    throw new IllegalArgumentException("media item list cannot be null or empty");
                 }
                 for (MediaItem item : items) {
                     if (item == null) {
diff --git a/media2/player/src/main/java/androidx/media2/player/PlaybackParams.java b/media2/player/src/main/java/androidx/media2/player/PlaybackParams.java
index c07fa42..e463802 100644
--- a/media2/player/src/main/java/androidx/media2/player/PlaybackParams.java
+++ b/media2/player/src/main/java/androidx/media2/player/PlaybackParams.java
@@ -202,6 +202,9 @@
          * @param playbackParams the non-null instance to initialize from.
          */
         public Builder(@NonNull PlaybackParams playbackParams) {
+            if (playbackParams == null) {
+                throw new NullPointerException("playbakcParams shouldn't be null");
+            }
             if (Build.VERSION.SDK_INT >= 23) {
                 mPlaybackParams = playbackParams.getPlaybackParams();
             } else {
@@ -252,10 +255,10 @@
         public @NonNull Builder setSpeed(
                 @FloatRange(from = 0.0f, to = Float.MAX_VALUE, fromInclusive = false) float speed) {
             if (speed == 0.f) {
-                throw new IllegalArgumentException("0 speed is not allowed.");
+                throw new IllegalArgumentException("0 speed is not allowed");
             }
             if (speed < 0.f) {
-                throw new IllegalArgumentException("negative speed is not supported.");
+                throw new IllegalArgumentException("negative speed is not supported");
             }
             if (Build.VERSION.SDK_INT >= 23) {
                 mPlaybackParams.setSpeed(speed);
diff --git a/media2/session/src/androidTest/java/androidx/media2/session/MediaSessionTest.java b/media2/session/src/androidTest/java/androidx/media2/session/MediaSessionTest.java
index 43ba9ba..afd584e 100644
--- a/media2/session/src/androidTest/java/androidx/media2/session/MediaSessionTest.java
+++ b/media2/session/src/androidTest/java/androidx/media2/session/MediaSessionTest.java
@@ -119,14 +119,14 @@
         try {
             builder = new MediaSession.Builder(mContext, null);
             fail("null player shouldn't be allowed");
-        } catch (IllegalArgumentException e) {
+        } catch (NullPointerException e) {
             // expected. pass-through
         }
         try {
             builder = new MediaSession.Builder(mContext, mPlayer);
             builder.setId(null);
             fail("null id shouldn't be allowed");
-        } catch (IllegalArgumentException e) {
+        } catch (NullPointerException e) {
             // expected. pass-through
         }
     }
diff --git a/media2/session/src/main/java/androidx/media2/session/MediaController.java b/media2/session/src/main/java/androidx/media2/session/MediaController.java
index ed50340..a65f845 100644
--- a/media2/session/src/main/java/androidx/media2/session/MediaController.java
+++ b/media2/session/src/main/java/androidx/media2/session/MediaController.java
@@ -137,19 +137,19 @@
      * @param callback controller callback to receive changes in
      */
     MediaController(@NonNull final Context context, @NonNull final SessionToken token,
-            @NonNull Bundle connectionHints, @NonNull Executor executor,
+            @Nullable Bundle connectionHints, @NonNull Executor executor,
             @NonNull ControllerCallback callback) {
         if (context == null) {
-            throw new IllegalArgumentException("context shouldn't be null");
+            throw new NullPointerException("context shouldn't be null");
         }
         if (token == null) {
-            throw new IllegalArgumentException("token shouldn't be null");
+            throw new NullPointerException("token shouldn't be null");
         }
         if (callback == null) {
-            throw new IllegalArgumentException("callback shouldn't be null");
+            throw new NullPointerException("callback shouldn't be null");
         }
         if (executor == null) {
-            throw new IllegalArgumentException("executor shouldn't be null");
+            throw new NullPointerException("executor shouldn't be null");
         }
         synchronized (mLock) {
             mImpl = createImpl(context, token, connectionHints, executor, callback);
@@ -165,19 +165,19 @@
      * @param callback controller callback to receive changes in
      */
     MediaController(@NonNull final Context context, @NonNull final MediaSessionCompat.Token token,
-            @NonNull final Bundle connectionHints, @NonNull final Executor executor,
+            @Nullable final Bundle connectionHints, @NonNull final Executor executor,
             @NonNull final ControllerCallback callback) {
         if (context == null) {
-            throw new IllegalArgumentException("context shouldn't be null");
+            throw new NullPointerException("context shouldn't be null");
         }
         if (token == null) {
-            throw new IllegalArgumentException("token shouldn't be null");
+            throw new NullPointerException("token shouldn't be null");
         }
         if (callback == null) {
-            throw new IllegalArgumentException("callback shouldn't be null");
+            throw new NullPointerException("callback shouldn't be null");
         }
         if (executor == null) {
-            throw new IllegalArgumentException("executor shouldn't be null");
+            throw new NullPointerException("executor shouldn't be null");
         }
         SessionToken.createSessionToken(context, token, executor,
                 new SessionToken.OnSessionTokenCreatedListener() {
@@ -434,7 +434,7 @@
     public ListenableFuture<SessionResult> playFromUri(@NonNull Uri uri,
             @Nullable Bundle extras) {
         if (uri == null) {
-            throw new IllegalArgumentException("uri shouldn't be null");
+            throw new NullPointerException("uri shouldn't be null");
         }
         if (isConnected()) {
             return getImpl().playFromUri(uri, extras);
@@ -511,7 +511,7 @@
     public ListenableFuture<SessionResult> prepareFromUri(@NonNull Uri uri,
             @Nullable Bundle extras) {
         if (uri == null) {
-            throw new IllegalArgumentException("uri shouldn't be null");
+            throw new NullPointerException("uri shouldn't be null");
         }
         if (isConnected()) {
             return getImpl().prepareFromUri(uri, extras);
@@ -687,11 +687,13 @@
     @NonNull
     public ListenableFuture<SessionResult> setRating(@NonNull String mediaId,
             @NonNull Rating rating) {
-        if (TextUtils.isEmpty(mediaId)) {
+        if (mediaId == null) {
+            throw new NullPointerException("mediaId shouldn't be null");
+        } else if (TextUtils.isEmpty(mediaId)) {
             throw new IllegalArgumentException("mediaId shouldn't be empty");
         }
         if (rating == null) {
-            throw new IllegalArgumentException("rating shouldn't be null");
+            throw new NullPointerException("rating shouldn't be null");
         }
         if (isConnected()) {
             return getImpl().setRating(mediaId, rating);
@@ -768,7 +770,7 @@
     public ListenableFuture<SessionResult> setPlaylist(@NonNull List<String> list,
             @Nullable MediaMetadata metadata) {
         if (list == null) {
-            throw new IllegalArgumentException("list shouldn't be null");
+            throw new NullPointerException("list shouldn't be null");
         }
         for (int i = 0; i < list.size(); i++) {
             if (TextUtils.isEmpty(list.get(i))) {
@@ -1261,7 +1263,7 @@
          */
         BuilderBase(@NonNull Context context) {
             if (context == null) {
-                throw new IllegalArgumentException("context shouldn't be null");
+                throw new NullPointerException("context shouldn't be null");
             }
             mContext = context;
         }
@@ -1306,7 +1308,7 @@
         @NonNull
         public U setSessionToken(@NonNull SessionToken token) {
             if (token == null) {
-                throw new IllegalArgumentException("token shouldn't be null");
+                throw new NullPointerException("token shouldn't be null");
             }
             mToken = token;
             mCompatToken = null;
@@ -1325,7 +1327,7 @@
         @NonNull
         public U setSessionCompatToken(@NonNull MediaSessionCompat.Token compatToken) {
             if (compatToken == null) {
-                throw new IllegalArgumentException("compatToken shouldn't be null");
+                throw new NullPointerException("compatToken shouldn't be null");
             }
             mCompatToken = compatToken;
             mToken = null;
@@ -1347,7 +1349,7 @@
         @NonNull
         public U setConnectionHints(@NonNull Bundle connectionHints) {
             if (connectionHints == null) {
-                throw new IllegalArgumentException("connectionHints shouldn't be null");
+                throw new NullPointerException("connectionHints shouldn't be null");
             }
             mConnectionHints = new Bundle(connectionHints);
             return (U) this;
@@ -1363,10 +1365,10 @@
         @NonNull
         public U setControllerCallback(@NonNull Executor executor, @NonNull C callback) {
             if (executor == null) {
-                throw new IllegalArgumentException("executor shouldn't be null");
+                throw new NullPointerException("executor shouldn't be null");
             }
             if (callback == null) {
-                throw new IllegalArgumentException("callback shouldn't be null");
+                throw new NullPointerException("callback shouldn't be null");
             }
             mCallbackExecutor = executor;
             mCallback = callback;
diff --git a/media2/session/src/main/java/androidx/media2/session/MediaControllerImplBase.java b/media2/session/src/main/java/androidx/media2/session/MediaControllerImplBase.java
index 9fc98a2..70dc487 100644
--- a/media2/session/src/main/java/androidx/media2/session/MediaControllerImplBase.java
+++ b/media2/session/src/main/java/androidx/media2/session/MediaControllerImplBase.java
@@ -162,16 +162,16 @@
             @Nullable Bundle connectionHints, Executor executor, ControllerCallback callback) {
         mInstance = instance;
         if (context == null) {
-            throw new IllegalArgumentException("context shouldn't be null");
+            throw new NullPointerException("context shouldn't be null");
         }
         if (token == null) {
-            throw new IllegalArgumentException("token shouldn't be null");
+            throw new NullPointerException("token shouldn't be null");
         }
         if (callback == null) {
-            throw new IllegalArgumentException("callback shouldn't be null");
+            throw new NullPointerException("callback shouldn't be null");
         }
         if (executor == null) {
-            throw new IllegalArgumentException("executor shouldn't be null");
+            throw new NullPointerException("executor shouldn't be null");
         }
         mContext = context;
         mSequencedFutureManager = new SequencedFutureManager();
diff --git a/media2/session/src/main/java/androidx/media2/session/MediaLibraryService.java b/media2/session/src/main/java/androidx/media2/session/MediaLibraryService.java
index 76adfdf..c0e23d6 100644
--- a/media2/session/src/main/java/androidx/media2/session/MediaLibraryService.java
+++ b/media2/session/src/main/java/androidx/media2/session/MediaLibraryService.java
@@ -339,9 +339,11 @@
                 @NonNull String parentId, @IntRange(from = 0) int itemCount,
                 @Nullable LibraryParams params) {
             if (controller == null) {
-                throw new IllegalArgumentException("controller shouldn't be null");
+                throw new NullPointerException("controller shouldn't be null");
             }
-            if (TextUtils.isEmpty(parentId)) {
+            if (parentId == null) {
+                throw new NullPointerException("parentId shouldn't be null");
+            } else if (TextUtils.isEmpty(parentId)) {
                 throw new IllegalArgumentException("parentId shouldn't be empty");
             }
             if (itemCount < 0) {
@@ -382,9 +384,11 @@
                 @NonNull String query, @IntRange(from = 0) int itemCount,
                 @Nullable LibraryParams params) {
             if (controller == null) {
-                throw new IllegalArgumentException("controller shouldn't be null");
+                throw new NullPointerException("controller shouldn't be null");
             }
-            if (TextUtils.isEmpty(query)) {
+            if (query == null) {
+                throw new NullPointerException("query shouldn't be null");
+            } else if (TextUtils.isEmpty(query)) {
                 throw new IllegalArgumentException("query shouldn't be empty");
             }
             if (itemCount < 0) {
diff --git a/media2/session/src/main/java/androidx/media2/session/MediaLibraryServiceLegacyStub.java b/media2/session/src/main/java/androidx/media2/session/MediaLibraryServiceLegacyStub.java
index d79cbdc..7ae46ce 100644
--- a/media2/session/src/main/java/androidx/media2/session/MediaLibraryServiceLegacyStub.java
+++ b/media2/session/src/main/java/androidx/media2/session/MediaLibraryServiceLegacyStub.java
@@ -288,7 +288,7 @@
         }
         if (!(controller.getControllerCb() instanceof BrowserLegacyCb)) {
             if (DEBUG) {
-                throw new IllegalStateException("Callback hasn't registered. Must be a bug.");
+                throw new IllegalStateException("Callback hasn't registered. Must be a bug");
             }
             return;
         }
diff --git a/media2/session/src/main/java/androidx/media2/session/MediaSession.java b/media2/session/src/main/java/androidx/media2/session/MediaSession.java
index b499caa..15da185 100644
--- a/media2/session/src/main/java/androidx/media2/session/MediaSession.java
+++ b/media2/session/src/main/java/androidx/media2/session/MediaSession.java
@@ -191,7 +191,7 @@
      */
     public void updatePlayer(@NonNull SessionPlayer player) {
         if (player == null) {
-            throw new IllegalArgumentException("player shouldn't be null");
+            throw new NullPointerException("player shouldn't be null");
         }
         mImpl.updatePlayer(player);
     }
@@ -295,10 +295,10 @@
     public @NonNull ListenableFuture<SessionResult> setCustomLayout(
             @NonNull ControllerInfo controller, @NonNull List<CommandButton> layout) {
         if (controller == null) {
-            throw new IllegalArgumentException("controller shouldn't be null");
+            throw new NullPointerException("controller shouldn't be null");
         }
         if (layout == null) {
-            throw new IllegalArgumentException("layout shouldn't be null");
+            throw new NullPointerException("layout shouldn't be null");
         }
         return mImpl.setCustomLayout(controller, layout);
     }
@@ -317,10 +317,10 @@
     public void setAllowedCommands(@NonNull ControllerInfo controller,
             @NonNull SessionCommandGroup commands) {
         if (controller == null) {
-            throw new IllegalArgumentException("controller shouldn't be null");
+            throw new NullPointerException("controller shouldn't be null");
         }
         if (commands == null) {
-            throw new IllegalArgumentException("commands shouldn't be null");
+            throw new NullPointerException("commands shouldn't be null");
         }
         mImpl.setAllowedCommands(controller, commands);
     }
@@ -360,10 +360,10 @@
             @NonNull ControllerInfo controller, @NonNull SessionCommand command,
             @Nullable Bundle args) {
         if (controller == null) {
-            throw new IllegalArgumentException("controller shouldn't be null");
+            throw new NullPointerException("controller shouldn't be null");
         }
         if (command == null) {
-            throw new IllegalArgumentException("command shouldn't be null");
+            throw new NullPointerException("command shouldn't be null");
         }
         if (command.getCommandCode() != SessionCommand.COMMAND_CODE_CUSTOM) {
             throw new IllegalArgumentException("command should be a custom command");
@@ -1237,10 +1237,10 @@
 
         BuilderBase(@NonNull Context context, @NonNull SessionPlayer player) {
             if (context == null) {
-                throw new IllegalArgumentException("context shouldn't be null");
+                throw new NullPointerException("context shouldn't be null");
             }
             if (player == null) {
-                throw new IllegalArgumentException("player shouldn't be null");
+                throw new NullPointerException("player shouldn't be null");
             }
             mContext = context;
             mPlayer = player;
@@ -1267,7 +1267,6 @@
          * wants to provide external apps to have finer controls of them.
          *
          * @param id id of the session. Must be unique per package.
-         * @throws IllegalArgumentException if id is {@code null}.
          * @return
          */
         // Note: This ID is not visible to the controllers. ID is introduced in order to prevent
@@ -1275,7 +1274,7 @@
         // sessions with the same ID in a process, then an IllegalStateException will be thrown.
         @NonNull U setId(@NonNull String id) {
             if (id == null) {
-                throw new IllegalArgumentException("id shouldn't be null");
+                throw new NullPointerException("id shouldn't be null");
             }
             mId = id;
             return (U) this;
@@ -1290,10 +1289,10 @@
          */
         @NonNull U setSessionCallback(@NonNull Executor executor, @NonNull C callback) {
             if (executor == null) {
-                throw new IllegalArgumentException("executor shouldn't be null");
+                throw new NullPointerException("executor shouldn't be null");
             }
             if (callback == null) {
-                throw new IllegalArgumentException("callback shouldn't be null");
+                throw new NullPointerException("callback shouldn't be null");
             }
             mCallbackExecutor = executor;
             mCallback = callback;
@@ -1310,7 +1309,7 @@
         @NonNull
         public U setExtras(@NonNull Bundle extras) {
             if (extras == null) {
-                throw new IllegalArgumentException("extras shouldn't be null");
+                throw new NullPointerException("extras shouldn't be null");
             }
             mExtras = extras;
             return (U) this;
diff --git a/media2/session/src/main/java/androidx/media2/session/MediaSessionImplBase.java b/media2/session/src/main/java/androidx/media2/session/MediaSessionImplBase.java
index a7b8e06..7cbef12 100644
--- a/media2/session/src/main/java/androidx/media2/session/MediaSessionImplBase.java
+++ b/media2/session/src/main/java/androidx/media2/session/MediaSessionImplBase.java
@@ -623,12 +623,12 @@
     @Override
     public ListenableFuture<PlayerResult> setPlaylist(final @NonNull List<MediaItem> list,
             final @Nullable MediaMetadata metadata) {
+        if (list == null) {
+            throw new NullPointerException("list shouldn't be null");
+        }
         return dispatchPlayerTask(new PlayerTask<ListenableFuture<PlayerResult>>() {
             @Override
             public ListenableFuture<PlayerResult> run(SessionPlayer player) throws Exception {
-                if (list == null) {
-                    throw new IllegalArgumentException("list shouldn't be null");
-                }
                 return player.setPlaylist(list, metadata);
             }
         });
@@ -636,12 +636,12 @@
 
     @Override
     public ListenableFuture<PlayerResult> setMediaItem(final @NonNull MediaItem item) {
+        if (item == null) {
+            throw new NullPointerException("item shouldn't be null");
+        }
         return dispatchPlayerTask(new PlayerTask<ListenableFuture<PlayerResult>>() {
             @Override
             public ListenableFuture<PlayerResult> run(SessionPlayer player) throws Exception {
-                if (item == null) {
-                    throw new IllegalArgumentException("item shouldn't be null");
-                }
                 return player.setMediaItem(item);
             }
         });
@@ -649,12 +649,12 @@
 
     @Override
     public ListenableFuture<PlayerResult> skipToPlaylistItem(final int index) {
+        if (index < 0) {
+            throw new IllegalArgumentException("index shouldn't be negative");
+        }
         return dispatchPlayerTask(new PlayerTask<ListenableFuture<PlayerResult>>() {
             @Override
             public ListenableFuture<PlayerResult> run(SessionPlayer player) throws Exception {
-                if (index < 0) {
-                    throw new IllegalArgumentException("index shouldn't be negative");
-                }
                 final List<MediaItem> list = player.getPlaylist();
                 if (index >= list.size()) {
                     return PlayerResult.createFuture(RESULT_ERROR_BAD_VALUE);
@@ -697,15 +697,15 @@
     @Override
     public ListenableFuture<PlayerResult> addPlaylistItem(final int index,
             final @NonNull MediaItem item) {
+        if (index < 0) {
+            throw new IllegalArgumentException("index shouldn't be negative");
+        }
+        if (item == null) {
+            throw new NullPointerException("item shouldn't be null");
+        }
         return dispatchPlayerTask(new PlayerTask<ListenableFuture<PlayerResult>>() {
             @Override
             public ListenableFuture<PlayerResult> run(SessionPlayer player) throws Exception {
-                if (index < 0) {
-                    throw new IllegalArgumentException("index shouldn't be negative");
-                }
-                if (item == null) {
-                    throw new IllegalArgumentException("item shouldn't be null");
-                }
                 return player.addPlaylistItem(index, item);
             }
         });
@@ -713,12 +713,12 @@
 
     @Override
     public ListenableFuture<PlayerResult> removePlaylistItem(final int index) {
+        if (index < 0) {
+            throw new IllegalArgumentException("index shouldn't be negative");
+        }
         return dispatchPlayerTask(new PlayerTask<ListenableFuture<PlayerResult>>() {
             @Override
             public ListenableFuture<PlayerResult> run(SessionPlayer player) throws Exception {
-                if (index < 0) {
-                    throw new IllegalArgumentException("index shouldn't be negative");
-                }
                 final List<MediaItem> list = player.getPlaylist();
                 if (index >= list.size()) {
                     return PlayerResult.createFuture(RESULT_ERROR_BAD_VALUE);
@@ -731,15 +731,15 @@
     @Override
     public ListenableFuture<PlayerResult> replacePlaylistItem(final int index,
             final @NonNull MediaItem item) {
+        if (index < 0) {
+            throw new IllegalArgumentException("index shouldn't be negative");
+        }
+        if (item == null) {
+            throw new NullPointerException("item shouldn't be null");
+        }
         return dispatchPlayerTask(new PlayerTask<ListenableFuture<PlayerResult>>() {
             @Override
             public ListenableFuture<PlayerResult> run(SessionPlayer player) throws Exception {
-                if (index < 0) {
-                    throw new IllegalArgumentException("index shouldn't be negative");
-                }
-                if (item == null) {
-                    throw new IllegalArgumentException("item shouldn't be null");
-                }
                 return player.replacePlaylistItem(index, item);
             }
         });
diff --git a/media2/session/src/main/java/androidx/media2/session/MediaSessionLegacyStub.java b/media2/session/src/main/java/androidx/media2/session/MediaSessionLegacyStub.java
index 27393f0..b68e37b 100644
--- a/media2/session/src/main/java/androidx/media2/session/MediaSessionLegacyStub.java
+++ b/media2/session/src/main/java/androidx/media2/session/MediaSessionLegacyStub.java
@@ -610,7 +610,7 @@
 
         @Override
         void onPlaybackInfoChanged(int seq, PlaybackInfo info) throws RemoteException {
-            throw new AssertionError("This shouldn't be called.");
+            throw new AssertionError("This shouldn't be called");
         }
 
         @Override
@@ -628,59 +628,59 @@
         @Override
         void onPlayerStateChanged(int seq, long eventTimeMs, long positionMs, int playerState)
                 throws RemoteException {
-            throw new AssertionError("This shouldn't be called.");
+            throw new AssertionError("This shouldn't be called");
         }
 
         @Override
         void onPlaybackSpeedChanged(int seq, long eventTimeMs, long positionMs, float speed)
                 throws RemoteException {
-            throw new AssertionError("This shouldn't be called.");
+            throw new AssertionError("This shouldn't be called");
         }
 
         @Override
         void onBufferingStateChanged(int seq, MediaItem item, int bufferingState,
                 long bufferedPositionMs, long eventTimeMs, long positionMs) throws RemoteException {
-            throw new AssertionError("This shouldn't be called.");
+            throw new AssertionError("This shouldn't be called");
         }
 
         @Override
         void onSeekCompleted(int seq, long eventTimeMs, long positionMs, long position)
                 throws RemoteException {
-            throw new AssertionError("This shouldn't be called.");
+            throw new AssertionError("This shouldn't be called");
         }
 
         @Override
         void onCurrentMediaItemChanged(int seq, MediaItem item, int currentIdx, int previousIdx,
                 int nextIdx) throws RemoteException {
-            throw new AssertionError("This shouldn't be called.");
+            throw new AssertionError("This shouldn't be called");
         }
 
         @Override
         void onPlaylistChanged(int seq, List<MediaItem> playlist, MediaMetadata metadata,
                 int currentIdx, int previousIdx, int nextIdx) throws RemoteException {
-            throw new AssertionError("This shouldn't be called.");
+            throw new AssertionError("This shouldn't be called");
         }
 
         @Override
         void onPlaylistMetadataChanged(int seq, MediaMetadata metadata) throws RemoteException {
-            throw new AssertionError("This shouldn't be called.");
+            throw new AssertionError("This shouldn't be called");
         }
 
         @Override
         void onShuffleModeChanged(int seq, int shuffleMode, int currentIdx, int previousIdx,
                 int nextIdx) throws RemoteException {
-            throw new AssertionError("This shouldn't be called.");
+            throw new AssertionError("This shouldn't be called");
         }
 
         @Override
         void onRepeatModeChanged(int seq, int repeatMode, int currentIdx, int previousIdx,
                 int nextIdx) throws RemoteException {
-            throw new AssertionError("This shouldn't be called.");
+            throw new AssertionError("This shouldn't be called");
         }
 
         @Override
         void onPlaybackCompleted(int seq) throws RemoteException {
-            throw new AssertionError("This shouldn't be called.");
+            throw new AssertionError("This shouldn't be called");
         }
 
         @Override
@@ -739,7 +739,7 @@
 
         @Override
         void setCustomLayout(int seq, List<CommandButton> layout) throws RemoteException {
-            throw new AssertionError("This shouldn't be called.");
+            throw new AssertionError("This shouldn't be called");
         }
 
         @Override
@@ -751,7 +751,7 @@
         @Override
         void onAllowedCommandsChanged(int seq, SessionCommandGroup commands)
                 throws RemoteException {
-            throw new AssertionError("This shouldn't be called.");
+            throw new AssertionError("This shouldn't be called");
         }
 
         @Override
diff --git a/media2/session/src/main/java/androidx/media2/session/MediaSessionManager.java b/media2/session/src/main/java/androidx/media2/session/MediaSessionManager.java
index 45c02b8..a578940 100644
--- a/media2/session/src/main/java/androidx/media2/session/MediaSessionManager.java
+++ b/media2/session/src/main/java/androidx/media2/session/MediaSessionManager.java
@@ -64,9 +64,10 @@
      *
      * @return the MediaSessionManager instance for this context.
      */
-    public static @NonNull MediaSessionManager getInstance(@NonNull Context context) {
+    @NonNull
+    public static MediaSessionManager getInstance(@NonNull Context context) {
         if (context == null) {
-            throw new IllegalArgumentException("context cannot be null");
+            throw new NullPointerException("context shouldn't be null");
         }
         synchronized (sLock) {
             if (sInstance == null) {
@@ -86,7 +87,8 @@
      *
      * @return set of tokens
      */
-    public @NonNull Set<SessionToken> getSessionServiceTokens() {
+    @NonNull
+    public Set<SessionToken> getSessionServiceTokens() {
         ArraySet<SessionToken> sessionServiceTokens = new ArraySet<>();
         PackageManager pm = mContext.getPackageManager();
         List<ResolveInfo> services = new ArrayList<>();
diff --git a/media2/session/src/main/java/androidx/media2/session/MediaSessionService.java b/media2/session/src/main/java/androidx/media2/session/MediaSessionService.java
index 444bf81..6ca32e0 100644
--- a/media2/session/src/main/java/androidx/media2/session/MediaSessionService.java
+++ b/media2/session/src/main/java/androidx/media2/session/MediaSessionService.java
@@ -188,7 +188,7 @@
      */
     public final void addSession(@NonNull MediaSession session) {
         if (session == null) {
-            throw new IllegalArgumentException("session shouldn't be null");
+            throw new NullPointerException("session shouldn't be null");
         }
         if (session.isClosed()) {
             throw new IllegalArgumentException("session is already closed");
@@ -204,7 +204,7 @@
      */
     public final void removeSession(@NonNull MediaSession session) {
         if (session == null) {
-            throw new IllegalArgumentException("session shouldn't be null");
+            throw new NullPointerException("session shouldn't be null");
         }
         mImpl.removeSession(session);
     }
@@ -226,7 +226,7 @@
      */
     public @Nullable MediaNotification onUpdateNotification(@NonNull MediaSession session) {
         if (session == null) {
-            throw new IllegalArgumentException("session shouldn't be null");
+            throw new NullPointerException("session shouldn't be null");
         }
         return mImpl.onUpdateNotification(session);
     }
@@ -298,7 +298,7 @@
          */
         public MediaNotification(int notificationId, @NonNull Notification notification) {
             if (notification == null) {
-                throw new IllegalArgumentException("notification shouldn't be null");
+                throw new NullPointerException("notification shouldn't be null");
             }
             mNotificationId = notificationId;
             mNotification = notification;
diff --git a/media2/session/src/main/java/androidx/media2/session/MediaSessionServiceImplBase.java b/media2/session/src/main/java/androidx/media2/session/MediaSessionServiceImplBase.java
index 9ab0ffe..caec9f1 100644
--- a/media2/session/src/main/java/androidx/media2/session/MediaSessionServiceImplBase.java
+++ b/media2/session/src/main/java/androidx/media2/session/MediaSessionServiceImplBase.java
@@ -131,7 +131,7 @@
             if (old != null && old != session) {
                 // TODO(b/112114183): Also check the uniqueness before sessions're returned by
                 //                    onGetSession.
-                throw new IllegalArgumentException("Session ID should be unique.");
+                throw new IllegalArgumentException("Session ID should be unique");
             }
             mSessions.put(session.getId(), session);
         }
diff --git a/media2/session/src/main/java/androidx/media2/session/MediaSessionStub.java b/media2/session/src/main/java/androidx/media2/session/MediaSessionStub.java
index ebc9bce..1dea1b6 100644
--- a/media2/session/src/main/java/androidx/media2/session/MediaSessionStub.java
+++ b/media2/session/src/main/java/androidx/media2/session/MediaSessionStub.java
@@ -394,10 +394,8 @@
 
     @SuppressWarnings("WeakerAccess") /* synthetic access */
     @Nullable
-    MediaItem convertMediaItemOnExecutor(ControllerInfo controller,
-            @NonNull String mediaId) {
+    MediaItem convertMediaItemOnExecutor(ControllerInfo controller, String mediaId) {
         if (TextUtils.isEmpty(mediaId)) {
-            Log.w(TAG, "Media ID shouldn't be null");
             return null;
         }
         MediaItem newItem = mSessionImpl.getCallback().onCreateMediaItem(
diff --git a/media2/session/src/main/java/androidx/media2/session/SessionCommand.java b/media2/session/src/main/java/androidx/media2/session/SessionCommand.java
index f2a1768..e7f8efa 100644
--- a/media2/session/src/main/java/androidx/media2/session/SessionCommand.java
+++ b/media2/session/src/main/java/androidx/media2/session/SessionCommand.java
@@ -578,7 +578,7 @@
      */
     public SessionCommand(@NonNull String action, @Nullable Bundle extras) {
         if (action == null) {
-            throw new IllegalArgumentException("action shouldn't be null");
+            throw new NullPointerException("action shouldn't be null");
         }
         mCommandCode = COMMAND_CODE_CUSTOM;
         mCustomAction = action;
diff --git a/media2/session/src/main/java/androidx/media2/session/SessionCommandGroup.java b/media2/session/src/main/java/androidx/media2/session/SessionCommandGroup.java
index 8059c26..2e7af16 100644
--- a/media2/session/src/main/java/androidx/media2/session/SessionCommandGroup.java
+++ b/media2/session/src/main/java/androidx/media2/session/SessionCommandGroup.java
@@ -66,7 +66,7 @@
      */
     public boolean hasCommand(@NonNull SessionCommand command) {
         if (command == null) {
-            throw new IllegalArgumentException("command shouldn't be null");
+            throw new NullPointerException("command shouldn't be null");
         }
         return mCommands.contains(command);
     }
@@ -112,6 +112,9 @@
          * @param commandGroup
          */
         public Builder(@NonNull SessionCommandGroup commandGroup) {
+            if (commandGroup == null) {
+                throw new NullPointerException("commandGroup shouldn't be null");
+            }
             mCommands = commandGroup.getCommands();
         }
 
@@ -122,7 +125,7 @@
          */
         public @NonNull Builder addCommand(@NonNull SessionCommand command) {
             if (command == null) {
-                throw new IllegalArgumentException("command shouldn't be null");
+                throw new NullPointerException("command shouldn't be null");
             }
             mCommands.add(command);
             return this;
@@ -159,7 +162,7 @@
          */
         public @NonNull Builder removeCommand(@NonNull SessionCommand command) {
             if (command == null) {
-                throw new IllegalArgumentException("command shouldn't be null");
+                throw new NullPointerException("command shouldn't be null");
             }
             mCommands.remove(command);
             return this;
diff --git a/media2/session/src/main/java/androidx/media2/session/SessionToken.java b/media2/session/src/main/java/androidx/media2/session/SessionToken.java
index 4231439..661a44c 100644
--- a/media2/session/src/main/java/androidx/media2/session/SessionToken.java
+++ b/media2/session/src/main/java/androidx/media2/session/SessionToken.java
@@ -121,6 +121,12 @@
      * @param serviceComponent The component name of the service.
      */
     public SessionToken(@NonNull Context context, @NonNull ComponentName serviceComponent) {
+        if (context == null) {
+            throw new NullPointerException("context shouldn't be null");
+        }
+        if (serviceComponent == null) {
+            throw new NullPointerException("serviceComponent shouldn't be null");
+        }
         final PackageManager manager = context.getPackageManager();
         final int uid = getUid(manager, serviceComponent.getPackageName());
 
@@ -137,7 +143,7 @@
         } else {
             throw new IllegalArgumentException(serviceComponent + " doesn't implement none of"
                     + " MediaSessionService, MediaLibraryService, MediaBrowserService nor"
-                    + " MediaBrowserServiceCompat. Use service's full name.");
+                    + " MediaBrowserServiceCompat. Use service's full name");
         }
         if (type != TYPE_BROWSER_SERVICE_LEGACY) {
             mImpl = new SessionTokenImplBase(serviceComponent, uid, type);
@@ -259,16 +265,16 @@
             @NonNull final MediaSessionCompat.Token tokenCompat, @NonNull final Executor executor,
             @NonNull final OnSessionTokenCreatedListener listener) {
         if (context == null) {
-            throw new IllegalArgumentException("context shouldn't be null");
+            throw new NullPointerException("context shouldn't be null");
         }
         if (tokenCompat == null) {
-            throw new IllegalArgumentException("token shouldn't be null");
+            throw new NullPointerException("token shouldn't be null");
         }
         if (executor == null) {
-            throw new IllegalArgumentException("executor shouldn't be null");
+            throw new NullPointerException("executor shouldn't be null");
         }
         if (listener == null) {
-            throw new IllegalArgumentException("listener shouldn't be null");
+            throw new NullPointerException("listener shouldn't be null");
         }
 
         try {
diff --git a/media2/session/src/main/java/androidx/media2/session/SessionTokenImplBase.java b/media2/session/src/main/java/androidx/media2/session/SessionTokenImplBase.java
index f6493c4..9c723c4 100644
--- a/media2/session/src/main/java/androidx/media2/session/SessionTokenImplBase.java
+++ b/media2/session/src/main/java/androidx/media2/session/SessionTokenImplBase.java
@@ -57,7 +57,7 @@
     @RestrictTo(LIBRARY_GROUP_PREFIX)
     SessionTokenImplBase(@NonNull ComponentName serviceComponent, int uid, int type) {
         if (serviceComponent == null) {
-            throw new IllegalArgumentException("serviceComponent shouldn't be null");
+            throw new NullPointerException("serviceComponent shouldn't be null");
         }
         mComponentName = serviceComponent;
         mPackageName = serviceComponent.getPackageName();
diff --git a/media2/session/src/main/java/androidx/media2/session/SessionTokenImplLegacy.java b/media2/session/src/main/java/androidx/media2/session/SessionTokenImplLegacy.java
index 7dc0eac..b8ae810 100644
--- a/media2/session/src/main/java/androidx/media2/session/SessionTokenImplLegacy.java
+++ b/media2/session/src/main/java/androidx/media2/session/SessionTokenImplLegacy.java
@@ -60,10 +60,12 @@
 
     SessionTokenImplLegacy(MediaSessionCompat.Token token, String packageName, int uid) {
         if (token == null) {
-            throw new IllegalArgumentException("token shouldn't be null.");
+            throw new NullPointerException("token shouldn't be null");
         }
-        if (TextUtils.isEmpty(packageName)) {
-            throw new IllegalArgumentException("packageName shouldn't be null.");
+        if (packageName == null) {
+            throw new NullPointerException("packageName shouldn't be null");
+        } else if (TextUtils.isEmpty(packageName)) {
+            throw new IllegalArgumentException("packageName shouldn't be empty");
         }
 
         mLegacyToken = token;
@@ -76,7 +78,7 @@
 
     SessionTokenImplLegacy(ComponentName serviceComponent, int uid) {
         if (serviceComponent == null) {
-            throw new IllegalArgumentException("serviceComponent shouldn't be null.");
+            throw new NullPointerException("serviceComponent shouldn't be null");
         }
 
         mLegacyToken = null;
diff --git a/media2/session/version-compat-tests/current/client/src/androidTest/java/androidx/media2/test/client/tests/MediaControllerTest.java b/media2/session/version-compat-tests/current/client/src/androidTest/java/androidx/media2/test/client/tests/MediaControllerTest.java
index de7016d0..6a0ad7a 100644
--- a/media2/session/version-compat-tests/current/client/src/androidTest/java/androidx/media2/test/client/tests/MediaControllerTest.java
+++ b/media2/session/version-compat-tests/current/client/src/androidTest/java/androidx/media2/test/client/tests/MediaControllerTest.java
@@ -103,7 +103,7 @@
         try {
             builder = new MediaController.Builder(null);
             fail("null context shouldn't be allowed");
-        } catch (IllegalArgumentException e) {
+        } catch (NullPointerException e) {
             // expected. pass-through
         }
 
@@ -111,7 +111,7 @@
             builder = new MediaController.Builder(mContext);
             builder.setSessionToken(null);
             fail("null token shouldn't be allowed");
-        } catch (IllegalArgumentException e) {
+        } catch (NullPointerException e) {
             // expected. pass-through
         }
 
@@ -119,7 +119,7 @@
             builder = new MediaController.Builder(mContext);
             builder.setSessionCompatToken(null);
             fail("null compat token shouldn't be allowed");
-        } catch (IllegalArgumentException e) {
+        } catch (NullPointerException e) {
             // expected. pass-through
         }
 
@@ -127,7 +127,7 @@
             builder = new MediaController.Builder(mContext);
             builder.setControllerCallback(null, null);
             fail("null executor or null callback shouldn't be allowed");
-        } catch (IllegalArgumentException e) {
+        } catch (NullPointerException e) {
             // expected. pass-through
         }
 
diff --git a/media2/session/version-compat-tests/current/service/src/androidTest/java/androidx/media2/test/service/tests/MediaSessionTest.java b/media2/session/version-compat-tests/current/service/src/androidTest/java/androidx/media2/test/service/tests/MediaSessionTest.java
index a1cdcf1..00688f4 100644
--- a/media2/session/version-compat-tests/current/service/src/androidTest/java/androidx/media2/test/service/tests/MediaSessionTest.java
+++ b/media2/session/version-compat-tests/current/service/src/androidTest/java/androidx/media2/test/service/tests/MediaSessionTest.java
@@ -102,21 +102,21 @@
         try {
             builder = new MediaSession.Builder(mContext, null);
             fail("null player shouldn't be allowed");
-        } catch (IllegalArgumentException e) {
+        } catch (NullPointerException e) {
             // expected. pass-through
         }
         try {
             builder = new MediaSession.Builder(mContext, mPlayer);
             builder.setId(null);
             fail("null id shouldn't be allowed");
-        } catch (IllegalArgumentException e) {
+        } catch (NullPointerException e) {
             // expected. pass-through
         }
         try {
             builder = new MediaSession.Builder(mContext, mPlayer);
             builder.setExtras(null);
             fail("null extras shouldn't be allowed");
-        } catch (IllegalArgumentException e) {
+        } catch (NullPointerException e) {
             // expected. pass-through
         }
     }
diff --git a/mediarouter/src/main/java/androidx/mediarouter/media/MediaRouteProvider.java b/mediarouter/src/main/java/androidx/mediarouter/media/MediaRouteProvider.java
index 9b93e5b..88798c5 100644
--- a/mediarouter/src/main/java/androidx/mediarouter/media/MediaRouteProvider.java
+++ b/mediarouter/src/main/java/androidx/mediarouter/media/MediaRouteProvider.java
@@ -512,10 +512,10 @@
                 @NonNull OnDynamicRoutesChangedListener listener) {
             synchronized (mLock) {
                 if (executor == null) {
-                    throw new NullPointerException("Executor shouldn't be null.");
+                    throw new NullPointerException("Executor shouldn't be null");
                 }
                 if (listener == null) {
-                    throw new NullPointerException("Listener shouldn't be null.");
+                    throw new NullPointerException("Listener shouldn't be null");
                 }
                 mExecutor = executor;
                 mListener = listener;
diff --git a/samples/Support7Demos/src/main/java/com/example/android/supportv7/widget/selection/fancy/FancySelectionDemoAdapter.java b/samples/Support7Demos/src/main/java/com/example/android/supportv7/widget/selection/fancy/FancySelectionDemoAdapter.java
index 0fcf599..5d2f5cb 100644
--- a/samples/Support7Demos/src/main/java/com/example/android/supportv7/widget/selection/fancy/FancySelectionDemoAdapter.java
+++ b/samples/Support7Demos/src/main/java/com/example/android/supportv7/widget/selection/fancy/FancySelectionDemoAdapter.java
@@ -48,7 +48,7 @@
             @Override
             public boolean isSelected(Uri id) {
                 throw new IllegalStateException(
-                        "Adapter must be initialized with SelectionTracker.");
+                        "Adapter must be initialized with SelectionTracker");
             }
         };