diff options
-rw-r--r-- | runtime/verifier/method_verifier.cc | 2 | ||||
-rw-r--r-- | test/161-final-abstract-class/expected.txt | 1 | ||||
-rw-r--r-- | test/161-final-abstract-class/info.txt | 1 | ||||
-rw-r--r-- | test/161-final-abstract-class/smali/AbstractFinal.smali | 16 | ||||
-rw-r--r-- | test/161-final-abstract-class/smali/TestClass.smali | 22 | ||||
-rw-r--r-- | test/161-final-abstract-class/src/Main.java | 48 |
6 files changed, 89 insertions, 1 deletions
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc index 38d151bc67..e09f95ce47 100644 --- a/runtime/verifier/method_verifier.cc +++ b/runtime/verifier/method_verifier.cc @@ -3732,7 +3732,7 @@ const RegType& MethodVerifier::ResolveClassAndCheckAccess(dex::TypeIndex class_i self_->ClearException(); } const RegType* result = nullptr; - if (klass != nullptr && !klass->IsErroneous()) { + if (klass != nullptr) { bool precise = klass->CannotBeAssignedFromOtherTypes(); if (precise && !IsInstantiableOrPrimitive(klass)) { const char* descriptor = dex_file_->StringByTypeIdx(class_idx); diff --git a/test/161-final-abstract-class/expected.txt b/test/161-final-abstract-class/expected.txt new file mode 100644 index 0000000000..1e635844cc --- /dev/null +++ b/test/161-final-abstract-class/expected.txt @@ -0,0 +1 @@ +java.lang.InstantiationError: AbstractFinal diff --git a/test/161-final-abstract-class/info.txt b/test/161-final-abstract-class/info.txt new file mode 100644 index 0000000000..2b7bee7a51 --- /dev/null +++ b/test/161-final-abstract-class/info.txt @@ -0,0 +1 @@ +Regression test for verifier crash when processing a final abstract (erroneous) class. diff --git a/test/161-final-abstract-class/smali/AbstractFinal.smali b/test/161-final-abstract-class/smali/AbstractFinal.smali new file mode 100644 index 0000000000..796fc40760 --- /dev/null +++ b/test/161-final-abstract-class/smali/AbstractFinal.smali @@ -0,0 +1,16 @@ +# 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 abstract final LAbstractFinal; +.super Ljava/lang/Object; diff --git a/test/161-final-abstract-class/smali/TestClass.smali b/test/161-final-abstract-class/smali/TestClass.smali new file mode 100644 index 0000000000..fa38f59854 --- /dev/null +++ b/test/161-final-abstract-class/smali/TestClass.smali @@ -0,0 +1,22 @@ +# 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 LTestClass; +.super Ljava/lang/Object; + +.method public static test()V + .registers 1 + new-instance v0, LAbstractFinal; + return-void +.end method diff --git a/test/161-final-abstract-class/src/Main.java b/test/161-final-abstract-class/src/Main.java new file mode 100644 index 0000000000..2452490226 --- /dev/null +++ b/test/161-final-abstract-class/src/Main.java @@ -0,0 +1,48 @@ +/* + * 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. + */ + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class Main { + public static void main(String[] args) { + try { + // Make sure that the abstract final class is marked as erroneous. + Class.forName("AbstractFinal"); + System.out.println("UNREACHABLE!"); + } catch (VerifyError expected) { + } catch (Throwable t) { + t.printStackTrace(System.out); + } + try { + // Verification of TestClass.test() used to crash when processing + // the final abstract (erroneous) class. + Class<?> tc = Class.forName("TestClass"); + Method test = tc.getDeclaredMethod("test"); + test.invoke(null); + System.out.println("UNREACHABLE!"); + } catch (InvocationTargetException ite) { + if (ite.getCause() instanceof InstantiationError) { + System.out.println( + ite.getCause().getClass().getName() + ": " + ite.getCause().getMessage()); + } else { + ite.printStackTrace(System.out); + } + } catch (Throwable t) { + t.printStackTrace(System.out); + } + } +} |