Skip to content

Commit e39bdc9

Browse files
author
Harold Seigel
committed
8274714: Incorrect verifier protected access error message
Reviewed-by: dholmes, coleenp
1 parent 45ce06c commit e39bdc9

File tree

3 files changed

+104
-2
lines changed

3 files changed

+104
-2
lines changed

src/hotspot/share/classfile/verifier.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,7 +1805,7 @@ void ClassVerifier::verify_method(const methodHandle& m, TRAPS) {
18051805
no_control_flow = true; break;
18061806
default:
18071807
// We only need to check the valid bytecodes in class file.
1808-
// And jsr and ret are not in the new class file format in JDK1.5.
1808+
// And jsr and ret are not in the new class file format in JDK1.6.
18091809
verify_error(ErrorContext::bad_code(bci),
18101810
"Bad instruction: %02x", opcode);
18111811
no_control_flow = false;
@@ -2424,7 +2424,8 @@ void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs,
24242424
verify_error(ErrorContext::bad_type(bci,
24252425
current_frame->stack_top_ctx(),
24262426
TypeOrigin::implicit(current_type())),
2427-
"Bad access to protected data in getfield");
2427+
"Bad access to protected data in %s",
2428+
is_getfield ? "getfield" : "putfield");
24282429
return;
24292430
}
24302431
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8274714
27+
* @summary Make sure error message for protected putfield error is correct.
28+
* @compile putfieldProtected.jasm
29+
* @run main/othervm -Xverify:remote PutfieldProtectedTest
30+
*/
31+
32+
// Test that an int[] is not assignable to byte[].
33+
public class PutfieldProtectedTest {
34+
35+
public static void main(String args[]) throws Throwable {
36+
try {
37+
Class newClass = Class.forName("other.putfieldProtected");
38+
throw new RuntimeException("Expected VerifyError exception not thrown");
39+
} catch (java.lang.VerifyError e) {
40+
if (!e.getMessage().contains("Bad access to protected data in putfield")) {
41+
throw new RuntimeException("wrong exception: " + e.getMessage());
42+
}
43+
}
44+
}
45+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
// This .jasm file is needed for this test to ensure that the illegal protected
25+
// access is done at runtime. Otherwise, javac would detect and complain about
26+
// the illegal access
27+
super public class another/SuperC version 51:0 {
28+
protected Field f:I;
29+
30+
public Method "<init>":"()V" stack 1 locals 1 {
31+
aload_0;
32+
invokespecial Method java/lang/Object."<init>":"()V";
33+
return;
34+
}
35+
} // end Class another/SuperC
36+
37+
38+
super public class other/putfieldProtected extends another/SuperC version 51:0 {
39+
40+
public Method "<init>":"()V" stack 1 locals 1 {
41+
aload_0;
42+
invokespecial Method another/SuperC."<init>":"()V";
43+
return;
44+
}
45+
46+
public static Method run:"()Z" stack 2 locals 2 {
47+
new class another/SuperC;
48+
dup;
49+
invokespecial Method another/SuperC."<init>":"()V";
50+
iconst_1;
51+
putfield Field another/SuperC.f:"I";
52+
iconst_1;
53+
ireturn;
54+
}
55+
56+
} // end Class other/putfieldProtected

0 commit comments

Comments
 (0)