diff options
| author | Elliott Hughes <enh@google.com> | 2013-02-22 17:04:54 -0800 |
|---|---|---|
| committer | Elliott Hughes <enh@google.com> | 2013-02-22 17:04:54 -0800 |
| commit | b0919815627858dff6d288e4d3567914e89b3661 (patch) | |
| tree | b0cb2513132ee011fa1c23aba2637b2ab0cf3738 | |
| parent | e3b5678ea4bea457f2190adea6745ddba673a75e (diff) | |
| download | android_dalvik-b0919815627858dff6d288e4d3567914e89b3661.tar.gz android_dalvik-b0919815627858dff6d288e4d3567914e89b3661.tar.bz2 android_dalvik-b0919815627858dff6d288e4d3567914e89b3661.zip | |
Abstract methods aren't implementations.
We should only be checking the visibility of actual implementations
of interface methods. Intervening abstract methods are allowed to
be non-public.
Bug: https://code.google.com/p/android/issues/detail?id=42991
Change-Id: I510d0cc6c1f89d161d4ebad7ef058c03fa09e9b0
| -rw-r--r-- | tests/301-abstract-protected/expected.txt | 1 | ||||
| -rw-r--r-- | tests/301-abstract-protected/info.txt | 3 | ||||
| -rw-r--r-- | tests/301-abstract-protected/src/Main.java | 33 | ||||
| -rw-r--r-- | vm/oo/Class.cpp | 4 |
4 files changed, 40 insertions, 1 deletions
diff --git a/tests/301-abstract-protected/expected.txt b/tests/301-abstract-protected/expected.txt new file mode 100644 index 000000000..b0aad4deb --- /dev/null +++ b/tests/301-abstract-protected/expected.txt @@ -0,0 +1 @@ +passed diff --git a/tests/301-abstract-protected/info.txt b/tests/301-abstract-protected/info.txt new file mode 100644 index 000000000..0751eff5a --- /dev/null +++ b/tests/301-abstract-protected/info.txt @@ -0,0 +1,3 @@ +Tests a dalvik bug where we'd treat an abstract method as an implementation +of an interface method; the RI only cares about the visibility of the actual +implementation in non-abstract subclasses. diff --git a/tests/301-abstract-protected/src/Main.java b/tests/301-abstract-protected/src/Main.java new file mode 100644 index 000000000..9b19a9d56 --- /dev/null +++ b/tests/301-abstract-protected/src/Main.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2013 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 Main { + public static void main(String args[]) throws Exception { + System.err.println(new C().m()); + } +} + +// An arbitrary interface. +interface I { public String m(); } + +// This is I-like, but doesn't actually claim to implement I. +abstract class Abstract { protected abstract String m(); } + +// This claims to implement I, but the inherited m isn't sufficiently visible. +abstract class AbstractI extends Abstract implements I { } + +// This has a concrete m that's sufficiently visible, so all should be good. +class C extends AbstractI { public String m() { return "passed"; }; } diff --git a/vm/oo/Class.cpp b/vm/oo/Class.cpp index 85ac9a72d..78a227310 100644 --- a/vm/oo/Class.cpp +++ b/vm/oo/Class.cpp @@ -3232,7 +3232,9 @@ static bool createIftable(ClassObject* clazz) == 0) { LOGVV("INTF: matched at %d", j); - if (!dvmIsPublicMethod(clazz->vtable[j])) { + if (!dvmIsAbstractMethod(clazz->vtable[j]) && + !dvmIsPublicMethod(clazz->vtable[j])) + { ALOGW("Implementation of %s.%s is not public", clazz->descriptor, clazz->vtable[j]->name); dvmThrowIllegalAccessError( |
