summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2021-03-23 14:57:03 +0000
committer Vladimir Marko <vmarko@google.com> 2021-03-24 09:17:10 +0000
commit8129ba3c95878db996f1578057c1e013daa6768a (patch)
treec50167bcec4c10c1cab99992005f1f6fb229f213
parent779761281e44bd209d57b8fc861f8aef88d57a73 (diff)
Add a test for wrong constructor resolution.
The constructor resolution in ART currently allows calling the superclass contructor directly. This is against the JLS but we do not try to fix it in this CL, just add a test that exposes the behavior. Test: New test in 162-method-resolution Test: testrunner.py --host -t 162-method-resolution Test: testrunner.py --jvm -t 162-method-resolution Bug: 183485797 Change-Id: I199584a09645b252e63ade903c0c43fef3e91819
-rw-r--r--test/162-method-resolution/expected-stdout.txt2
-rw-r--r--test/162-method-resolution/jasmin/Test11User.j25
-rw-r--r--test/162-method-resolution/src/Main.java33
-rw-r--r--test/162-method-resolution/src/Test11Base.java21
-rw-r--r--test/162-method-resolution/src/Test11Derived.java21
5 files changed, 102 insertions, 0 deletions
diff --git a/test/162-method-resolution/expected-stdout.txt b/test/162-method-resolution/expected-stdout.txt
index f440fbf6b4..4f3f443449 100644
--- a/test/162-method-resolution/expected-stdout.txt
+++ b/test/162-method-resolution/expected-stdout.txt
@@ -43,3 +43,5 @@ Caught java.lang.reflect.InvocationTargetException
Calling Test10User.test():
Caught java.lang.reflect.InvocationTargetException
caused by java.lang.IncompatibleClassChangeError
+Calling Test11User.test():
+Test11Base.<init>("Test")
diff --git a/test/162-method-resolution/jasmin/Test11User.j b/test/162-method-resolution/jasmin/Test11User.j
new file mode 100644
index 0000000000..ded6e7a919
--- /dev/null
+++ b/test/162-method-resolution/jasmin/Test11User.j
@@ -0,0 +1,25 @@
+; Copyright (C) 2021 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.
+
+.class public Test11User
+.super java/lang/Object
+
+.method public static test()V
+ .limit stack 2
+ .limit locals 2
+ new Test11Derived
+ ldc "Test"
+ invokespecial Test11Derived.<init>(Ljava/lang/String;)V
+ return
+.end method
diff --git a/test/162-method-resolution/src/Main.java b/test/162-method-resolution/src/Main.java
index a855ac6f89..e0ad6b8933 100644
--- a/test/162-method-resolution/src/Main.java
+++ b/test/162-method-resolution/src/Main.java
@@ -37,6 +37,7 @@ public class Main {
test8();
test9();
test10();
+ test11();
// TODO: How to test that interface method resolution returns the unique
// maximally-specific non-abstract superinterface method if there is one?
@@ -406,6 +407,38 @@ public class Main {
}
}
+ /*
+ * Test11
+ * ------
+ * Tested function:
+ * public class Test11Base {
+ * Test11Base(String) { ... }
+ * }
+ * public class Test11Derived extends Test11Base {
+ * Test11Derived() { Test11Base("Test"); }
+ * }
+ * Tested invokes:
+ * invoke-direct Test11Derived.<init>(Ljava/lang/String;)V from Test11User in first dex
+ * TODO b/183485797 This should throw a NSME (constructors are never inherited, JLS 8.8)
+ * but actually calls the superclass constructor.
+ * expected: Throws NoSuchMethodError
+ * actual: Successful construction of a Test11Derived instance.
+ *
+ * Files:
+ * src/Test11Base.java - defines Test11Base with <init>(Ljava/lang/String;)V
+ * src/Test11Derived.java - defines Test11Derived with <init>()V
+ * jasmin/Test11User.j - invokespecial Test11Derived.<init>(Ljava/lang/String;)V
+ */
+ private static void test11() throws Exception {
+ if (usingRI) {
+ // For RI, just print the expected output to hide the divergence for now.
+ System.out.println("Calling Test11User.test():\n" +
+ "Test11Base.<init>(\"Test\")");
+ } else {
+ invokeUserTest("Test11User");
+ }
+ }
+
private static void invokeUserTest(String userName) throws Exception {
System.out.println("Calling " + userName + ".test():");
try {
diff --git a/test/162-method-resolution/src/Test11Base.java b/test/162-method-resolution/src/Test11Base.java
new file mode 100644
index 0000000000..20fab3ab8b
--- /dev/null
+++ b/test/162-method-resolution/src/Test11Base.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+public class Test11Base {
+ Test11Base(String message) {
+ System.out.println("Test11Base.<init>(\"" + message + "\")");
+ }
+}
diff --git a/test/162-method-resolution/src/Test11Derived.java b/test/162-method-resolution/src/Test11Derived.java
new file mode 100644
index 0000000000..ab0e8ae9a5
--- /dev/null
+++ b/test/162-method-resolution/src/Test11Derived.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+public class Test11Derived extends Test11Base {
+ Test11Derived() {
+ super("Test11Derived");
+ }
+}