Fix OldRuntimeTest#test_load(library)?Deprecated
Test was checking for a wrong exception type,
should be UnsupportedOperationException not
IllegalStateException.
Also addresses formatting and visibility nits from
post-merge comments.
Change-Id: Ic9834501fbc741d2677041c0e434d559cda76101
Test: libcore.java.lang.OldRuntimeTest
Bug: 25859957
diff --git a/luni/src/test/java/libcore/java/lang/OldRuntimeTest.java b/luni/src/test/java/libcore/java/lang/OldRuntimeTest.java
index 5c4d1c6..8397587 100644
--- a/luni/src/test/java/libcore/java/lang/OldRuntimeTest.java
+++ b/luni/src/test/java/libcore/java/lang/OldRuntimeTest.java
@@ -522,6 +522,7 @@
//expected
}
}
+
// b/25859957
public void test_loadDeprecated() throws Exception {
final int savedTargetSdkVersion = VMRuntime.getRuntime().getTargetSdkVersion();
@@ -529,10 +530,9 @@
try {
// Call Runtime#load(String, ClassLoader) at API level 24 (N). It will fail
// with a UnsatisfiedLinkError because requested library doesn't exits.
- VMRuntime.getRuntime()
- .setTargetSdkVersion(24);
- Method loadMethod = Runtime.class.getDeclaredMethod("load", String.class,
- ClassLoader.class);
+ VMRuntime.getRuntime().setTargetSdkVersion(24);
+ Method loadMethod =
+ Runtime.class.getDeclaredMethod("load", String.class, ClassLoader.class);
loadMethod.setAccessible(true);
loadMethod.invoke(Runtime.getRuntime(), "nonExistentLibrary", null);
fail();
@@ -543,15 +543,14 @@
try {
// Call Runtime#load(String, ClassLoader) at API level 25. It will fail
// with a IllegalStateException because it's deprecated.
- VMRuntime.getRuntime()
- .setTargetSdkVersion(25);
- Method loadMethod = Runtime.class.getDeclaredMethod("load", String.class,
- ClassLoader.class);
+ VMRuntime.getRuntime().setTargetSdkVersion(25);
+ Method loadMethod =
+ Runtime.class.getDeclaredMethod("load", String.class, ClassLoader.class);
loadMethod.setAccessible(true);
loadMethod.invoke(Runtime.getRuntime(), "nonExistentLibrary", null);
fail();
} catch(InvocationTargetException expected) {
- assertTrue(expected.getCause() instanceof IllegalStateException);
+ assertTrue(expected.getCause() instanceof UnsupportedOperationException);
}
} finally {
VMRuntime.getRuntime().setTargetSdkVersion(savedTargetSdkVersion);
@@ -565,10 +564,9 @@
try {
// Call Runtime#loadLibrary(String, ClassLoader) at API level 24 (N). It will fail
// with a UnsatisfiedLinkError because requested library doesn't exits.
- VMRuntime.getRuntime()
- .setTargetSdkVersion(24);
- Method loadMethod = Runtime.class.getDeclaredMethod("loadLibrary", String.class,
- ClassLoader.class);
+ VMRuntime.getRuntime().setTargetSdkVersion(24);
+ Method loadMethod =
+ Runtime.class.getDeclaredMethod("loadLibrary", String.class, ClassLoader.class);
loadMethod.setAccessible(true);
loadMethod.invoke(Runtime.getRuntime(), "nonExistentLibrary", null);
fail();
@@ -580,19 +578,17 @@
// Call Runtime#load(String, ClassLoader) at API level 25. It will fail
// with a IllegalStateException because it's deprecated.
- VMRuntime.getRuntime()
- .setTargetSdkVersion(25);
- Method loadMethod = Runtime.class.getDeclaredMethod("loadLibrary", String.class,
- ClassLoader.class);
+ VMRuntime.getRuntime().setTargetSdkVersion(25);
+ Method loadMethod =
+ Runtime.class.getDeclaredMethod("loadLibrary", String.class, ClassLoader.class);
loadMethod.setAccessible(true);
loadMethod.invoke(Runtime.getRuntime(), "nonExistentLibrary", null);
fail();
} catch(InvocationTargetException expected) {
- assertTrue(expected.getCause() instanceof IllegalStateException);
+ assertTrue(expected.getCause() instanceof UnsupportedOperationException);
}
} finally {
VMRuntime.getRuntime().setTargetSdkVersion(savedTargetSdkVersion);
}
}
-
}
diff --git a/ojluni/src/main/java/java/lang/Runtime.java b/ojluni/src/main/java/java/lang/Runtime.java
index 24c7e89..5e63dd8 100755
--- a/ojluni/src/main/java/java/lang/Runtime.java
+++ b/ojluni/src/main/java/java/lang/Runtime.java
@@ -872,7 +872,7 @@
}
/** Check target sdk, if it's higher than N, we throw an UnsupportedOperationException */
- void checkTargetSdkVersionForLoad(String methodName) {
+ private void checkTargetSdkVersionForLoad(String methodName) {
final int targetSdkVersion = VMRuntime.getRuntime().getTargetSdkVersion();
if (targetSdkVersion > 24) {
throw new UnsupportedOperationException(methodName + " is not supported on SDK " +