Adding CollectionIncompatibleType error_prone

CollectionIncompatibleType rules (go/error-prone).
calling Map#remove() not on a key result in the object to
never be removed from the map.

Fixing the semantic only. Teams should ensure that test is
still behaving as expected.

Test: make cts javac-check -j76 TARGET_PRODUCT=aosp_arm64
WITH_DEXPREOPT=false RUN_ERROR_PRONE=true
Bug: 37854485

Change-Id: Ibb2f83d5712ea191358b7945cd6b32b8c1517fa6
diff --git a/error_prone_rules_tests.mk b/error_prone_rules_tests.mk
index 46c69ec..1effdba 100644
--- a/error_prone_rules_tests.mk
+++ b/error_prone_rules_tests.mk
@@ -15,7 +15,8 @@
 # Set of error prone rules to ensure code quality of tests
 
 # Goal is to eventually merge with error_prone_rules.mk
-LOCAL_ERROR_PRONE_FLAGS:= -Xep:EqualsNaN:ERROR \
+LOCAL_ERROR_PRONE_FLAGS:= -Xep:CollectionIncompatibleType:ERROR \
+                          -Xep:EqualsNaN:ERROR \
                           -Xep:FormatString:ERROR \
                           -Xep:JUnit3TestNotRun:ERROR \
                           -Xep:TryFailThrowable:ERROR
diff --git a/hostsidetests/appsecurity/test-apps/DocumentProvider/src/com/android/cts/documentprovider/MyDocumentsProvider.java b/hostsidetests/appsecurity/test-apps/DocumentProvider/src/com/android/cts/documentprovider/MyDocumentsProvider.java
index edf6f15..91abb89 100644
--- a/hostsidetests/appsecurity/test-apps/DocumentProvider/src/com/android/cts/documentprovider/MyDocumentsProvider.java
+++ b/hostsidetests/appsecurity/test-apps/DocumentProvider/src/com/android/cts/documentprovider/MyDocumentsProvider.java
@@ -256,7 +256,7 @@
     @Override
     public void deleteDocument(String documentId) throws FileNotFoundException {
         final Doc doc = mDocs.get(documentId);
-        mDocs.remove(doc);
+        mDocs.remove(doc.docId);
         for (Doc parentDoc : mDocs.values()) {
             parentDoc.children.remove(doc);
         }
@@ -268,7 +268,7 @@
         // There are no multi-parented documents in this provider, so it's safe to remove the
         // document from mDocs.
         final Doc doc = mDocs.get(documentId);
-        mDocs.remove(doc);
+        mDocs.remove(doc.docId);
         mDocs.get(parentDocumentId).children.remove(doc);
     }
 
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_Images_ThumbnailsTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_Images_ThumbnailsTest.java
index 62a041b..b0f5426 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_Images_ThumbnailsTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_Images_ThumbnailsTest.java
@@ -125,10 +125,11 @@
             fail("There is no sdcard attached! " + e.getMessage());
         }
         assertNotNull(stringUrl);
-        mRowsAdded.add(Uri.parse(stringUrl));
+        Uri stringUri = Uri.parse(stringUrl);
+        mRowsAdded.add(stringUri);
 
         // get the original image id and path
-        Cursor c = mContentResolver.query(Uri.parse(stringUrl),
+        Cursor c = mContentResolver.query(stringUri,
                 new String[]{ Media._ID, Media.DATA }, null, null, null);
         c.moveToFirst();
         long imageId = c.getLong(c.getColumnIndex(Media._ID));
@@ -165,8 +166,8 @@
         // deleting the image from the database also deletes the image file, and the
         // corresponding entry in the thumbnail table, which in turn triggers deletion
         // of the thumbnail file on disk
-        mContentResolver.delete(Uri.parse(stringUrl), null, null);
-        mRowsAdded.remove(stringUrl);
+        mContentResolver.delete(stringUri, null, null);
+        mRowsAdded.remove(stringUri);
 
         assertFalse("image file should no longer exist", new File(imagePath).exists());
 
diff --git a/tools/vm-tests-tf/Android.mk b/tools/vm-tests-tf/Android.mk
index d367f65..8c820b4 100644
--- a/tools/vm-tests-tf/Android.mk
+++ b/tools/vm-tests-tf/Android.mk
@@ -25,7 +25,7 @@
 LOCAL_MODULE_CLASS := JAVA_LIBRARIES
 LOCAL_MODULE_TAGS := optional
 LOCAL_JAVA_LIBRARIES := junit
-
+-include cts/error_prone_rules_tests.mk
 include $(BUILD_JAVA_LIBRARY)
 
 cts-tf-dalvik-lib.jack := $(full_classes_jack)
diff --git a/tools/vm-tests-tf/src/dot/junit/opcodes/opc_throw/Test_opc_throw.java b/tools/vm-tests-tf/src/dot/junit/opcodes/opc_throw/Test_opc_throw.java
index 7baf67d..df1e017 100644
--- a/tools/vm-tests-tf/src/dot/junit/opcodes/opc_throw/Test_opc_throw.java
+++ b/tools/vm-tests-tf/src/dot/junit/opcodes/opc_throw/Test_opc_throw.java
@@ -47,10 +47,11 @@
         T_opc_throw_2 t = new T_opc_throw_2();
         try {
             t.run();
-            fail("must throw a Throwable");
         } catch (Throwable e) {
             // expected
+            return;
         }
+        fail("must throw a Throwable");
     }
 
     /**
@@ -60,10 +61,11 @@
         T_opc_throw_8 t = new T_opc_throw_8();
         try {
             t.run();
-            fail("must throw a Error");
         } catch (Error e) {
             // expected
+            return;
         }
+        fail("must throw a Error");
     }
 
     /**