summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/class_linker.cc4
-rw-r--r--test/166-bad-interface-super/expected.txt2
-rw-r--r--test/166-bad-interface-super/info.txt1
-rw-r--r--test/166-bad-interface-super/jasmin/BadSuper1.j17
-rw-r--r--test/166-bad-interface-super/jasmin/BadSuper2.j17
-rw-r--r--test/166-bad-interface-super/src/BaseClass.java18
-rw-r--r--test/166-bad-interface-super/src/BaseInterface.java18
-rw-r--r--test/166-bad-interface-super/src/Main.java31
8 files changed, 108 insertions, 0 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 38dd7612f2..ccf431969a 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -5523,6 +5523,10 @@ bool ClassLinker::LinkSuperClass(Handle<mirror::Class> klass) {
return false;
}
// Verify
+ if (klass->IsInterface() && super != GetClassRoot(kJavaLangObject)) {
+ ThrowClassFormatError(klass.Get(), "Interfaces must have java.lang.Object as superclass");
+ return false;
+ }
if (super->IsFinal()) {
ThrowVerifyError(klass.Get(),
"Superclass %s of %s is declared final",
diff --git a/test/166-bad-interface-super/expected.txt b/test/166-bad-interface-super/expected.txt
new file mode 100644
index 0000000000..c49f6d255f
--- /dev/null
+++ b/test/166-bad-interface-super/expected.txt
@@ -0,0 +1,2 @@
+Caught java.lang.ClassFormatError when trying to resolve BadSuper1.
+Caught java.lang.ClassFormatError when trying to resolve BadSuper2.
diff --git a/test/166-bad-interface-super/info.txt b/test/166-bad-interface-super/info.txt
new file mode 100644
index 0000000000..bcba8c0d89
--- /dev/null
+++ b/test/166-bad-interface-super/info.txt
@@ -0,0 +1 @@
+Test that linking an interface declaring a superclass other than j.l.Object throws CFE.
diff --git a/test/166-bad-interface-super/jasmin/BadSuper1.j b/test/166-bad-interface-super/jasmin/BadSuper1.j
new file mode 100644
index 0000000000..f96564ec73
--- /dev/null
+++ b/test/166-bad-interface-super/jasmin/BadSuper1.j
@@ -0,0 +1,17 @@
+; Copyright (C) 2017 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.
+
+.interface public BadSuper1
+.super BaseInterface
+
diff --git a/test/166-bad-interface-super/jasmin/BadSuper2.j b/test/166-bad-interface-super/jasmin/BadSuper2.j
new file mode 100644
index 0000000000..584bd2094d
--- /dev/null
+++ b/test/166-bad-interface-super/jasmin/BadSuper2.j
@@ -0,0 +1,17 @@
+; Copyright (C) 2017 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.
+
+.interface public BadSuper2
+.super BaseClass
+
diff --git a/test/166-bad-interface-super/src/BaseClass.java b/test/166-bad-interface-super/src/BaseClass.java
new file mode 100644
index 0000000000..6ea1ad3f3b
--- /dev/null
+++ b/test/166-bad-interface-super/src/BaseClass.java
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2017 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 BaseClass {
+}
diff --git a/test/166-bad-interface-super/src/BaseInterface.java b/test/166-bad-interface-super/src/BaseInterface.java
new file mode 100644
index 0000000000..7872a43794
--- /dev/null
+++ b/test/166-bad-interface-super/src/BaseInterface.java
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+interface BaseInterface {
+}
diff --git a/test/166-bad-interface-super/src/Main.java b/test/166-bad-interface-super/src/Main.java
new file mode 100644
index 0000000000..3df2574678
--- /dev/null
+++ b/test/166-bad-interface-super/src/Main.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2017 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 Main {
+ public static void main(String[] args) throws Exception {
+ tryResolveClassExpectingCFE("BadSuper1");
+ tryResolveClassExpectingCFE("BadSuper2");
+ }
+
+ public static void tryResolveClassExpectingCFE(String className) throws Exception {
+ try {
+ Class.forName(className);
+ } catch (ClassFormatError e) {
+ System.out.println(
+ "Caught " + e.getClass().getName() + " when trying to resolve " + className + ".");
+ }
+ }
+}