Merge "Fix 58 libcore tests that caught "expected" Exceptions but didn't fail()" am: 20440a97a3 am: afd3d3d9c1
am: 3077ee121b

Change-Id: Ic9f6e1bf7f9bd34e565f363f82eac139ac8235ed
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/ChannelsTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/ChannelsTest.java
index bd7a1ad..274628a 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/ChannelsTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/ChannelsTest.java
@@ -507,6 +507,7 @@
         // null channel
         try {
             Writer testWriter = Channels.newWriter(null, Charset.forName(CODE_SET).newEncoder(), -1);
+            fail();
         } catch (NullPointerException expected) {
         }
 
@@ -514,6 +515,7 @@
         this.fouts = null;
         try {
             WritableByteChannel wbChannel = Channels.newChannel(this.fouts);
+            fail();
         } catch (NullPointerException expected) {
         }
     }
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/FileChannelTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/FileChannelTest.java
index d6dacb4..03c472c 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/FileChannelTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/FileChannelTest.java
@@ -1367,6 +1367,7 @@
         ByteBuffer readBuffer = ByteBuffer.allocate(CAPACITY);
         try {
             readOnlyFileChannel.read(readBuffer, Long.MAX_VALUE);
+            fail();
         } catch (IOException expected) {
         }
     }
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/SimpleDateFormatTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/SimpleDateFormatTest.java
index 9237fac..16217b2 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/SimpleDateFormatTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/SimpleDateFormatTest.java
@@ -641,11 +641,13 @@
         SimpleDateFormat pFormat = new SimpleDateFormat("h z", Locale.ENGLISH);
         try {
             pFormat.parse("14 GMT-23");
+            fail();
         } catch (ParseException expected) {
         }
 
         try {
             pFormat.parse("14 GMT+23");
+            fail();
         } catch (ParseException expected) {
         }
     }
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/IdentityHashMapTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/IdentityHashMapTest.java
index ee1a372..d68a923 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/IdentityHashMapTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/IdentityHashMapTest.java
@@ -1080,6 +1080,7 @@
                     return "";
                 }
             });
+            fail();
         } catch (ConcurrentModificationException expected) {}
     }
 
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLEngineTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLEngineTest.java
index 9360c00..8fae7b8 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLEngineTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLEngineTest.java
@@ -894,6 +894,7 @@
         SSLEngine sse = getEngine(host, port);
 
         try {
+            // TODO: decide whether OpenSSLEngineImpl should throw ISE (it doesn't) b/31301555
             SSLEngineResult result = sse.wrap(bbs, bbd);
         } catch (IllegalStateException expected) {
         }
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java
index 861f4a8..a791a77 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java
@@ -249,6 +249,7 @@
 
         try {
             ssl.removeHandshakeCompletedListener(ls);
+            fail();
         } catch (IllegalArgumentException expected) {
         }
 
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/TrustManagerFactory1Test.java b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/TrustManagerFactory1Test.java
index 9b5b929..176a832 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/TrustManagerFactory1Test.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/TrustManagerFactory1Test.java
@@ -295,6 +295,7 @@
         for (String validValue : getValidValues()) {
             try {
                 TrustManagerFactory.getInstance(validValue, (Provider) null);
+                fail();
             } catch (IllegalArgumentException expected) {
             }
         }
diff --git a/luni/src/test/java/libcore/java/lang/ref/FinalizeTest.java b/luni/src/test/java/libcore/java/lang/ref/FinalizeTest.java
index 55e70033..6962671 100644
--- a/luni/src/test/java/libcore/java/lang/ref/FinalizeTest.java
+++ b/luni/src/test/java/libcore/java/lang/ref/FinalizeTest.java
@@ -72,9 +72,16 @@
     // Helper function since we do not want a vreg to keep the allocated object live.
     // For b/25851249
     private void exceptionInConstructor() {
+        boolean thrown = false;
         try {
             new ConstructionFails();
+            // can't fail() here since AssertionFailedError extends AssertionError, which
+            // we expect
         } catch (AssertionError expected) {
+            thrown = true;
+        }
+        if (!thrown) {
+            fail();
         }
     }
 
diff --git a/luni/src/test/java/libcore/java/net/AbstractCookiesTest.java b/luni/src/test/java/libcore/java/net/AbstractCookiesTest.java
index d6424a0..d4d650f 100644
--- a/luni/src/test/java/libcore/java/net/AbstractCookiesTest.java
+++ b/luni/src/test/java/libcore/java/net/AbstractCookiesTest.java
@@ -530,6 +530,7 @@
         assertEquals(Arrays.asList(cookieA), cookieStore.getCookies());
         try {
             cookieStore.add(null, cookieB);
+            fail();
         } catch (NullPointerException expected) {
         }
         assertEquals(Arrays.asList(cookieA, cookieB), cookieStore.getCookies());
diff --git a/luni/src/test/java/libcore/java/net/SocketTest.java b/luni/src/test/java/libcore/java/net/SocketTest.java
index e2d3964..6f1ce29 100644
--- a/luni/src/test/java/libcore/java/net/SocketTest.java
+++ b/luni/src/test/java/libcore/java/net/SocketTest.java
@@ -531,21 +531,27 @@
         // Test all Socket ctors
         try {
             new SocketThatFailOnClose("localhost", 1);
+            fail();
         } catch(IOException expected) {}
         try {
             new SocketThatFailOnClose(InetAddress.getLocalHost(), 1);
+            fail();
         } catch(IOException expected) {}
         try {
             new SocketThatFailOnClose("localhost", 1, null, 0);
+            fail();
         } catch(IOException expected) {}
         try {
             new SocketThatFailOnClose(InetAddress.getLocalHost(), 1, null, 0);
+            fail();
         } catch(IOException expected) {}
         try {
             new SocketThatFailOnClose("localhost", 1, true);
+            fail();
         } catch(IOException expected) {}
         try {
             new SocketThatFailOnClose(InetAddress.getLocalHost(), 1, true);
+            fail();
         } catch(IOException expected) {}
     }
 
diff --git a/luni/src/test/java/libcore/java/nio/channels/AsynchronousChannelGroupTest.java b/luni/src/test/java/libcore/java/nio/channels/AsynchronousChannelGroupTest.java
index 28e30e0..0ddf0bc 100644
--- a/luni/src/test/java/libcore/java/nio/channels/AsynchronousChannelGroupTest.java
+++ b/luni/src/test/java/libcore/java/nio/channels/AsynchronousChannelGroupTest.java
@@ -99,6 +99,7 @@
         // It should not be possible to bind a new channel.
         try {
             AsynchronousServerSocketChannel.open(acg);
+            fail();
         } catch (ShutdownChannelGroupException expected) {}
 
         // ExecutorService hasn't yet terminated as the channel is still open.
@@ -127,6 +128,7 @@
         // It should not be possible to bind a new channel.
         try {
             AsynchronousServerSocketChannel.open(acg);
+            fail();
         } catch (ShutdownChannelGroupException expected) {}
 
         acg.shutdownNow();
diff --git a/luni/src/test/java/libcore/java/nio/channels/DatagramChannelMulticastTest.java b/luni/src/test/java/libcore/java/nio/channels/DatagramChannelMulticastTest.java
index 1e7cefe..0951302 100644
--- a/luni/src/test/java/libcore/java/nio/channels/DatagramChannelMulticastTest.java
+++ b/luni/src/test/java/libcore/java/nio/channels/DatagramChannelMulticastTest.java
@@ -1156,11 +1156,13 @@
 
         try {
             membershipKey.block(UNICAST_IPv4_1);
+            fail();
         } catch (IllegalStateException expected) {
         }
 
         try {
             membershipKey.unblock(UNICAST_IPv4_1);
+            fail();
         } catch (IllegalStateException expected) {
         }
 
diff --git a/luni/src/test/java/libcore/java/nio/channels/DatagramChannelTest.java b/luni/src/test/java/libcore/java/nio/channels/DatagramChannelTest.java
index f3bd7ff..6943a53 100644
--- a/luni/src/test/java/libcore/java/nio/channels/DatagramChannelTest.java
+++ b/luni/src/test/java/libcore/java/nio/channels/DatagramChannelTest.java
@@ -209,6 +209,7 @@
         socketAddress = new InetSocketAddress(Inet4Address.LOOPBACK, 0);
         try {
             channel.bind(socketAddress);
+            fail();
         } catch (ClosedChannelException expected) {}
     }
 
diff --git a/luni/src/test/java/libcore/java/nio/channels/MembershipKeyTest.java b/luni/src/test/java/libcore/java/nio/channels/MembershipKeyTest.java
index 43cc26d..7f385a0 100644
--- a/luni/src/test/java/libcore/java/nio/channels/MembershipKeyTest.java
+++ b/luni/src/test/java/libcore/java/nio/channels/MembershipKeyTest.java
@@ -161,6 +161,7 @@
         init(true);
         try {
             key.block(sourceAddress);
+            fail();
         } catch (IllegalStateException expected) {}
     }
 
diff --git a/luni/src/test/java/libcore/java/nio/channels/SocketChannelTest.java b/luni/src/test/java/libcore/java/nio/channels/SocketChannelTest.java
index 72609ee..9cd916d 100644
--- a/luni/src/test/java/libcore/java/nio/channels/SocketChannelTest.java
+++ b/luni/src/test/java/libcore/java/nio/channels/SocketChannelTest.java
@@ -321,6 +321,7 @@
         socketAddress = new InetSocketAddress(Inet4Address.LOOPBACK, 0);
         try {
             sc.bind(socketAddress);
+            fail();
         } catch (ClosedChannelException expected) {
         }
     }
diff --git a/luni/src/test/java/libcore/java/util/CollectionsTest.java b/luni/src/test/java/libcore/java/util/CollectionsTest.java
index f3284c0..3c951b5 100644
--- a/luni/src/test/java/libcore/java/util/CollectionsTest.java
+++ b/luni/src/test/java/libcore/java/util/CollectionsTest.java
@@ -28,6 +28,7 @@
 import java.util.NoSuchElementException;
 import java.util.Spliterator;
 
+import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 public final class CollectionsTest extends TestCase {
@@ -629,12 +630,14 @@
         checkedMap2.putIfAbsent(1, A_STRING);
         try {
             checkedMap2.putIfAbsent(1, NOT_A_STRING);
+            fail();
         } catch (ClassCastException expected) {}
 
         // When key is absent
         checkedMap2.clear();
         try {
             checkedMap2.putIfAbsent(1, NOT_A_STRING);
+            fail();
         } catch (ClassCastException expected) {}
     }
 
@@ -657,6 +660,7 @@
 
         try {
             checkedMap2.replace(1, NOT_A_STRING);
+            fail();
         } catch (ClassCastException expected) {}
     }
 
@@ -672,6 +676,7 @@
 
         try {
             checkedMap2.replace(1, 1, NOT_A_STRING);
+            fail();
         } catch (ClassCastException expected) {}
     }
 
@@ -685,15 +690,16 @@
         Map checkedMap2 = Collections.checkedMap(new HashMap<>(), Integer.class, String.class);
         checkedMap2.put(1, A_STRING);
 
-        // When key is present
-        try {
-            checkedMap2.computeIfAbsent(1, k -> NOT_A_STRING);
-        } catch (ClassCastException expected) {}
+        // When key is present, function should not be invoked
+        assertSame(A_STRING, checkedMap2.computeIfAbsent(1, k -> {
+            throw new AssertionFailedError("key present: function should not be invoked");
+        }));
 
-        // When key is absent
+        // When key is absent, computed value's type should be checked
         checkedMap2.clear();
         try {
             checkedMap2.computeIfAbsent(1, k -> NOT_A_STRING);
+            fail();
         } catch (ClassCastException expected) {}
     }
 
@@ -709,6 +715,7 @@
 
         try {
             checkedMap2.computeIfPresent(1, (k, v) -> NOT_A_STRING);
+            fail();
         } catch (ClassCastException expected) {}
     }
 
@@ -721,6 +728,7 @@
         checkedMap2.put(1, A_STRING);
         try {
             checkedMap2.compute(1, (k, v) -> NOT_A_STRING);
+            fail();
         } catch (ClassCastException expected) {}
     }
 
@@ -736,6 +744,7 @@
 
         try {
             checkedMap2.merge(1, A_STRING, (v1, v2) -> NOT_A_STRING);
+            fail();
         } catch (ClassCastException expected) {}
     }
 }
diff --git a/luni/src/test/java/libcore/java/util/HashtableTest.java b/luni/src/test/java/libcore/java/util/HashtableTest.java
index ca2027c..4a61147 100644
--- a/luni/src/test/java/libcore/java/util/HashtableTest.java
+++ b/luni/src/test/java/libcore/java/util/HashtableTest.java
@@ -101,6 +101,7 @@
 
         try {
             ht.replaceAll((k, v) -> null);
+            fail();
         } catch (NullPointerException expected) {}
     }
 
diff --git a/luni/src/test/java/libcore/java/util/concurrent/CopyOnWriteArrayListTest.java b/luni/src/test/java/libcore/java/util/concurrent/CopyOnWriteArrayListTest.java
index 631cc30..4d9a648 100644
--- a/luni/src/test/java/libcore/java/util/concurrent/CopyOnWriteArrayListTest.java
+++ b/luni/src/test/java/libcore/java/util/concurrent/CopyOnWriteArrayListTest.java
@@ -318,11 +318,6 @@
         assertEquals(-3.0, l.get(0));
         assertEquals(2.0, l.get(1));
         assertEquals(5.0, l.get(2));
-
-        try {
-            l.sort((v1, v2) -> v1.compareTo(v2));
-        } catch (NullPointerException expected) {
-        }
     }
 
     public void test_forEach() {
@@ -341,6 +336,7 @@
 
         try {
             l.forEach(null);
+            fail();
         } catch (NullPointerException expected) {
         }
     }
@@ -406,11 +402,6 @@
         assertEquals(9, (int)completeList.get(3));
         assertEquals(22, (int)completeList.get(4));
         assertEquals(12, (int)completeList.get(5));
-
-        try {
-            l.sort((v1, v2) -> v1.compareTo(v2));
-        } catch (NullPointerException expected) {
-        }
     }
 
     public void test_subList_forEach() {
@@ -430,6 +421,7 @@
 
         try {
             l.forEach(null);
+            fail();
         } catch (NullPointerException expected) {
         }
     }
diff --git a/luni/src/test/java/libcore/java/util/prefs/OldPreferenceChangeEventTest.java b/luni/src/test/java/libcore/java/util/prefs/OldPreferenceChangeEventTest.java
index d77a11c..2f07129 100644
--- a/luni/src/test/java/libcore/java/util/prefs/OldPreferenceChangeEventTest.java
+++ b/luni/src/test/java/libcore/java/util/prefs/OldPreferenceChangeEventTest.java
@@ -130,13 +130,6 @@
         private boolean addDispatched = false;
         protected boolean result = false;
 
-        public synchronized void waitForEvent() {
-            try {
-                wait(500);
-            } catch (InterruptedException expected) {
-            }
-        }
-
         public synchronized void preferenceChange(PreferenceChangeEvent pce) {
             changed++;
             addDispatched = true;
diff --git a/luni/src/test/java/libcore/java/util/zip/AbstractZipFileTest.java b/luni/src/test/java/libcore/java/util/zip/AbstractZipFileTest.java
index 9e049c0..a6e400e 100644
--- a/luni/src/test/java/libcore/java/util/zip/AbstractZipFileTest.java
+++ b/luni/src/test/java/libcore/java/util/zip/AbstractZipFileTest.java
@@ -458,6 +458,7 @@
         // setCrc takes a long, not an int, so -1 isn't a valid CRC32 (because it's 64 bits).
         try {
             ze.setCrc(-1);
+            fail();
         } catch (IllegalArgumentException expected) {
         }
 
diff --git a/luni/src/test/java/libcore/javax/crypto/CipherTest.java b/luni/src/test/java/libcore/javax/crypto/CipherTest.java
index b26147a..1127559 100644
--- a/luni/src/test/java/libcore/javax/crypto/CipherTest.java
+++ b/luni/src/test/java/libcore/javax/crypto/CipherTest.java
@@ -1300,6 +1300,7 @@
 
         try {
             c.getOutputSize(0);
+            fail();
         } catch (IllegalStateException expected) {
         }
 
diff --git a/luni/src/test/java/libcore/javax/net/ssl/KeyStoreBuilderParametersTest.java b/luni/src/test/java/libcore/javax/net/ssl/KeyStoreBuilderParametersTest.java
index 5b8f6e6..d73e4a3 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/KeyStoreBuilderParametersTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/KeyStoreBuilderParametersTest.java
@@ -47,6 +47,7 @@
     public void test_init_List_null() {
         try {
             new KeyStoreBuilderParameters((List) null);
+            fail();
         } catch (NullPointerException expected) {
         }
     }
diff --git a/luni/src/test/java/libcore/javax/net/ssl/SSLContextTest.java b/luni/src/test/java/libcore/javax/net/ssl/SSLContextTest.java
index 533849c..603baa1 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/SSLContextTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/SSLContextTest.java
@@ -57,6 +57,7 @@
         assertNotNull(sslContext);
         try {
             sslContext.init(null, null, null);
+            fail();
         } catch (KeyManagementException expected) {
         }
     }
@@ -64,6 +65,7 @@
     public void test_SSLContext_setDefault() throws Exception {
         try {
             SSLContext.setDefault(null);
+            fail();
         } catch (NullPointerException expected) {
         }
 
diff --git a/luni/src/test/java/libcore/javax/net/ssl/SSLSessionTest.java b/luni/src/test/java/libcore/javax/net/ssl/SSLSessionTest.java
index bc2b626..5691dfb 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/SSLSessionTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/SSLSessionTest.java
@@ -242,6 +242,7 @@
         TestSSLSessions s = TestSSLSessions.create();
         try {
             s.invalid.getValue(null);
+            fail();
         } catch (IllegalArgumentException expected) {
         }
         assertNull(s.invalid.getValue("BOGUS"));
diff --git a/luni/src/test/java/libcore/xml/KxmlSerializerTest.java b/luni/src/test/java/libcore/xml/KxmlSerializerTest.java
index 5f68a99..fffb3f1 100644
--- a/luni/src/test/java/libcore/xml/KxmlSerializerTest.java
+++ b/luni/src/test/java/libcore/xml/KxmlSerializerTest.java
@@ -129,14 +129,17 @@
         serializer.startTag(NAMESPACE, "tag");
         try {
             serializer.attribute(NAMESPACE, "attr", "a\ud83d\u0040b");
+            fail();
         } catch (IllegalArgumentException expected) {
         }
         try {
             serializer.text("c\ud83d\u0040d");
+            fail();
         } catch (IllegalArgumentException expected) {
         }
         try {
             serializer.cdsect("e\ud83d\u0040f");
+            fail();
         } catch (IllegalArgumentException expected) {
         }
     }
diff --git a/luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherTest.java b/luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherTest.java
index b4da1b8..e893670 100644
--- a/luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherTest.java
+++ b/luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherTest.java
@@ -561,6 +561,7 @@
         }
         try {
             Cipher.getMaxAllowedKeyLength("");
+            fail();
         } catch (NoSuchAlgorithmException expected) {
         }
         try {
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java
index a768863..61c6d03 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java
@@ -530,6 +530,7 @@
         uc2.connect();
         try {
             uc2.getInputStream();
+            fail();
         } catch (Throwable expected) {
         }
     }
diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java
index d303903..dd325b1 100644
--- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java
+++ b/luni/src/test/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java
@@ -892,6 +892,7 @@
 
         try {
             keyStore.entryInstanceOf(null, KeyStore.SecretKeyEntry.class);
+            fail();
         } catch (NullPointerException expected) {
         }
 
@@ -924,6 +925,7 @@
 
         try {
             keyStore.store(new ByteArrayOutputStream(), "pwd".toCharArray());
+            fail();
         } catch (KeyStoreException expected) {
         }
 
diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreSpiTest.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreSpiTest.java
index a85459b..be3e6d1 100644
--- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreSpiTest.java
+++ b/luni/src/test/java/org/apache/harmony/security/tests/java/security/KeyStoreSpiTest.java
@@ -77,18 +77,12 @@
                 KeyStore.TrustedCertificateEntry.class));
 
         try {
-            assertFalse(ksSpi.engineEntryInstanceOf(null,
-                    KeyStore.TrustedCertificateEntry.class));
+            ksSpi.engineEntryInstanceOf(null, KeyStore.TrustedCertificateEntry.class);
+            fail();
         } catch (NullPointerException expected) {
         }
 
-        try {
-            assertFalse(ksSpi.engineEntryInstanceOf(
-                    "test_engineEntryInstanceOf_Alias1", null));
-        } catch (NullPointerException expected) {
-        }
-
-
+        assertFalse(ksSpi.engineEntryInstanceOf("test_engineEntryInstanceOf_Alias1", null));
     }
 
     public void testKeyStoreSpi01() throws IOException,
@@ -111,6 +105,7 @@
 
         try {
             ksSpi.engineStore(null);
+            fail();
         } catch (UnsupportedOperationException expected) {
         }
         assertNull("Not null entry", ksSpi.engineGetEntry("aaa", null));
diff --git a/luni/src/test/java/tests/security/cert/X509CertSelectorTest.java b/luni/src/test/java/tests/security/cert/X509CertSelectorTest.java
index 1616efb..1ef25fd 100644
--- a/luni/src/test/java/tests/security/cert/X509CertSelectorTest.java
+++ b/luni/src/test/java/tests/security/cert/X509CertSelectorTest.java
@@ -859,6 +859,7 @@
         for (int i = 0; i < invalidValues.length; i++) {
             try {
                 selector.setBasicConstraints(-3);
+                fail();
             } catch (IllegalArgumentException expected) {
             }
         }
diff --git a/luni/src/test/java/tests/security/cert/X509Certificate2Test.java b/luni/src/test/java/tests/security/cert/X509Certificate2Test.java
index 03b0243..bf736d5 100644
--- a/luni/src/test/java/tests/security/cert/X509Certificate2Test.java
+++ b/luni/src/test/java/tests/security/cert/X509Certificate2Test.java
@@ -306,16 +306,19 @@
 
         try {
             l.clear();
+            fail();
         } catch (UnsupportedOperationException expected) {
         }
 
         try {
             l.add("Test");
+            fail();
         } catch (UnsupportedOperationException expected) {
         }
 
         try {
             l.remove(0);
+            fail();
         } catch (UnsupportedOperationException expected) {
         }
     }