diff --git a/NativeCode.bp b/NativeCode.bp index 9b45cb018b8..8b0757821ba 100644 --- a/NativeCode.bp +++ b/NativeCode.bp @@ -203,6 +203,7 @@ cc_library_shared { srcs: [ "luni/src/test/native/libcore_dalvik_system_JniTest.cpp", "luni/src/test/native/libcore_java_io_FileTest.cpp", + "luni/src/test/native/libcore_java_lang_OldStackTraceElementTest.cpp", "luni/src/test/native/libcore_java_lang_ThreadTest.cpp", "luni/src/test/native/libcore_java_nio_BufferTest.cpp", "luni/src/test/native/libcore_java_time_TimeApisConsistencyTest.cpp", diff --git a/luni/src/test/java/libcore/java/lang/OldStackTraceElementTest.java b/luni/src/test/java/libcore/java/lang/OldStackTraceElementTest.java index 9a09c458f2f..4c0c31dace7 100644 --- a/luni/src/test/java/libcore/java/lang/OldStackTraceElementTest.java +++ b/luni/src/test/java/libcore/java/lang/OldStackTraceElementTest.java @@ -25,12 +25,16 @@ public class Original extends TestCase { public void pureJavaMethod(Object test) throws Exception { throw new Exception("pure java method"); } + } - native public void pureNativeMethod(Object test); + static { + System.loadLibrary("javacoretests"); } private Original original; + private native void pureNativeMethod(); + @Override protected void setUp() throws Exception { original = new Original(); @@ -185,9 +189,9 @@ public void test_isNativeMethod() { e.getStackTrace()[0].isNativeMethod()); } try { - original.pureNativeMethod(new Object()); + pureNativeMethod(); fail(); - } catch (Error e) { + } catch (UnsupportedOperationException e) { assertTrue("Incorrect method type", e.getStackTrace()[0].isNativeMethod()); } diff --git a/luni/src/test/native/libcore_java_lang_OldStackTraceElementTest.cpp b/luni/src/test/native/libcore_java_lang_OldStackTraceElementTest.cpp new file mode 100644 index 00000000000..08ded2f3b46 --- /dev/null +++ b/luni/src/test/native/libcore_java_lang_OldStackTraceElementTest.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +extern "C" void Java_libcore_java_lang_OldStackTraceElementTest_pureNativeMethod( + JNIEnv* env, jobject /* clazz */) { + jniThrowException(env, "java/lang/UnsupportedOperationException", "Throwing Exception!"); + return; +}