Skip to content

Commit

Permalink
8243583: Change 'final' error checks to throw ICCE
Browse files Browse the repository at this point in the history
Reviewed-by: lfoltan, dholmes
  • Loading branch information
Harold Seigel committed Oct 28, 2020
1 parent 1f00c3b commit 3bd5b80
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
23 changes: 7 additions & 16 deletions src/hotspot/share/classfile/classFileParser.cpp
Expand Up @@ -4438,13 +4438,7 @@ void ClassFileParser::check_super_class_access(const InstanceKlass* this_klass,
const InstanceKlass* super_ik = InstanceKlass::cast(super);

if (super->is_final()) {
ResourceMark rm(THREAD);
Exceptions::fthrow(
THREAD_AND_LOCATION,
vmSymbols::java_lang_VerifyError(),
"class %s cannot inherit from final class %s",
this_klass->external_name(),
super_ik->external_name());
classfile_icce_error("class %s cannot inherit from final class %s", super_ik, THREAD);
return;
}

Expand Down Expand Up @@ -4589,15 +4583,12 @@ static void check_final_method_override(const InstanceKlass* this_klass, TRAPS)
if (can_access) {
// this class can access super final method and therefore override
ResourceMark rm(THREAD);
Exceptions::fthrow(THREAD_AND_LOCATION,
vmSymbols::java_lang_VerifyError(),
"class %s overrides final method %s.%s%s",
this_klass->external_name(),
super_m->method_holder()->external_name(),
name->as_C_string(),
signature->as_C_string()
);
return;
THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
err_msg("class %s overrides final method %s.%s%s",
this_klass->external_name(),
super_m->method_holder()->external_name(),
name->as_C_string(),
signature->as_C_string()));
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/hotspot/jtreg/runtime/verifier/OverriderMsg.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -128,7 +128,7 @@ public static void main(String... args) throws Exception {
ProcessBuilder pb = ProcessTools.createTestJvm("-cp", ".", "Overrider");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldContain(
"java.lang.VerifyError: class Overrider overrides final method HasFinal.m(Ljava/lang/String;)V");
"java.lang.IncompatibleClassChangeError: class Overrider overrides final method HasFinal.m(Ljava/lang/String;)V");
output.shouldHaveExitValue(1);
}

Expand Down
Expand Up @@ -30,9 +30,9 @@
* VM Testbase keywords: [feature_mlvm]
* VM Testbase readme:
* DESCRIPTION
* Try to load anonymous class derived from java.lang.System. The verification
* system (split verifier and system class loader) should reject such attempt and
* throw VerifyError.
* Try to load anonymous class derived from java.lang.System. The class file
* loader should reject such attempt and throw IncompatibleClassChangeError
* because java.lang.System is a final class.
*
* @library /vmTestbase
* /test/lib
Expand All @@ -44,6 +44,6 @@
* @run main/othervm
* vm.mlvm.anonloader.share.ReplaceClassParentTest
* -newParent java/lang/System
* -requireExceptions java.lang.VerifyError
* -requireExceptions java.lang.IncompatibleClassChangeError
*/

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -123,7 +123,7 @@ public void testGetClass() throws Exception {

ConcreteClass C = b.clazz("C").implement(I).build();

b.test().loadClass(I).throws_(VerifyError.class).done()
b.test().loadClass(I).throws_(IncompatibleClassChangeError.class).done()
.run();
}

Expand Down Expand Up @@ -158,7 +158,7 @@ public void testNotify() throws Exception {

ConcreteClass C = b.clazz("C").implement(I).build();

b.test().loadClass(I).throws_(VerifyError.class).done()
b.test().loadClass(I).throws_(IncompatibleClassChangeError.class).done()
.run();
}

Expand All @@ -174,7 +174,7 @@ public void testNotifyAll() throws Exception {

ConcreteClass C = b.clazz("C").implement(I).build();

b.test().loadClass(I).throws_(VerifyError.class).done()
b.test().loadClass(I).throws_(IncompatibleClassChangeError.class).done()
.run();
}

Expand Down Expand Up @@ -208,7 +208,7 @@ public void testWait() throws Exception {

ConcreteClass C = b.clazz("C").implement(I).build();

b.test().loadClass(I).throws_(VerifyError.class).done()
b.test().loadClass(I).throws_(IncompatibleClassChangeError.class).done()
.run();
}

Expand All @@ -224,7 +224,7 @@ public void testTimedWait() throws Exception {

ConcreteClass C = b.clazz("C").implement(I).build();

b.test().loadClass(I).throws_(VerifyError.class).done()
b.test().loadClass(I).throws_(IncompatibleClassChangeError.class).done()
.run();
}

Expand All @@ -240,7 +240,7 @@ public void testTimedWait1() throws Exception {

ConcreteClass C = b.clazz("C").implement(I).build();

b.test().loadClass(I).throws_(VerifyError.class).done()
b.test().loadClass(I).throws_(IncompatibleClassChangeError.class).done()
.run();
}
}

1 comment on commit 3bd5b80

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 3bd5b80 Oct 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.