From 8ade7ed80a6d60aab9f2cafb76946dc2aec973e8 Mon Sep 17 00:00:00 2001 From: Victor Chang Date: Wed, 27 Jul 2022 15:32:47 +0100 Subject: [PATCH] Fix a warning in OldStackTraceElementTest due to missing JNI method implementation This doesn't fix b/240239515, but just fix the warning occured in the logs. Bug: 240239515 Test: atest CtsLibcoreTestCases:libcore.java.lang.OldStackTraceElementTest Change-Id: Ibba4cb9d60430c57eb1c24878421e105b8d5d5d6 --- NativeCode.bp | 1 + .../java/lang/OldStackTraceElementTest.java | 10 +++++--- ...ore_java_lang_OldStackTraceElementTest.cpp | 24 +++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 luni/src/test/native/libcore_java_lang_OldStackTraceElementTest.cpp diff --git a/NativeCode.bp b/NativeCode.bp index f1b7427cb50..b37690cbcdb 100644 --- a/NativeCode.bp +++ b/NativeCode.bp @@ -205,6 +205,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; +}