Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8274714: Incorrect verifier protected access error message
Reviewed-by: dholmes, coleenp
  • Loading branch information
Harold Seigel committed Oct 21, 2021
1 parent 45ce06c commit e39bdc9
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/hotspot/share/classfile/verifier.cpp
Expand Up @@ -1805,7 +1805,7 @@ void ClassVerifier::verify_method(const methodHandle& m, TRAPS) {
no_control_flow = true; break;
default:
// We only need to check the valid bytecodes in class file.
// And jsr and ret are not in the new class file format in JDK1.5.
// And jsr and ret are not in the new class file format in JDK1.6.
verify_error(ErrorContext::bad_code(bci),
"Bad instruction: %02x", opcode);
no_control_flow = false;
Expand Down Expand Up @@ -2424,7 +2424,8 @@ void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs,
verify_error(ErrorContext::bad_type(bci,
current_frame->stack_top_ctx(),
TypeOrigin::implicit(current_type())),
"Bad access to protected data in getfield");
"Bad access to protected data in %s",
is_getfield ? "getfield" : "putfield");
return;
}
}
Expand Down
45 changes: 45 additions & 0 deletions test/hotspot/jtreg/runtime/verifier/PutfieldProtectedTest.java
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2021, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @bug 8274714
* @summary Make sure error message for protected putfield error is correct.
* @compile putfieldProtected.jasm
* @run main/othervm -Xverify:remote PutfieldProtectedTest
*/

// Test that an int[] is not assignable to byte[].
public class PutfieldProtectedTest {

public static void main(String args[]) throws Throwable {
try {
Class newClass = Class.forName("other.putfieldProtected");
throw new RuntimeException("Expected VerifyError exception not thrown");
} catch (java.lang.VerifyError e) {
if (!e.getMessage().contains("Bad access to protected data in putfield")) {
throw new RuntimeException("wrong exception: " + e.getMessage());
}
}
}
}
56 changes: 56 additions & 0 deletions test/hotspot/jtreg/runtime/verifier/putfieldProtected.jasm
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2021, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

// This .jasm file is needed for this test to ensure that the illegal protected
// access is done at runtime. Otherwise, javac would detect and complain about
// the illegal access
super public class another/SuperC version 51:0 {
protected Field f:I;

public Method "<init>":"()V" stack 1 locals 1 {
aload_0;
invokespecial Method java/lang/Object."<init>":"()V";
return;
}
} // end Class another/SuperC


super public class other/putfieldProtected extends another/SuperC version 51:0 {

public Method "<init>":"()V" stack 1 locals 1 {
aload_0;
invokespecial Method another/SuperC."<init>":"()V";
return;
}

public static Method run:"()Z" stack 2 locals 2 {
new class another/SuperC;
dup;
invokespecial Method another/SuperC."<init>":"()V";
iconst_1;
putfield Field another/SuperC.f:"I";
iconst_1;
ireturn;
}

} // end Class other/putfieldProtected

5 comments on commit e39bdc9

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on e39bdc9 Dec 7, 2021

Choose a reason for hiding this comment

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

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on e39bdc9 Dec 7, 2021

Choose a reason for hiding this comment

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

@GoeLin the backport was successfully created on the branch GoeLin-backport-e39bdc9d in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit e39bdc9d from the openjdk/jdk repository.

The commit being backported was authored by Harold Seigel on 21 Oct 2021 and was reviewed by David Holmes and Coleen Phillimore.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev GoeLin-backport-e39bdc9d:GoeLin-backport-e39bdc9d
$ git checkout GoeLin-backport-e39bdc9d
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev GoeLin-backport-e39bdc9d

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on e39bdc9 Dec 20, 2021

Choose a reason for hiding this comment

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

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on e39bdc9 Dec 20, 2021

Choose a reason for hiding this comment

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

@GoeLin the backport was successfully created on the branch GoeLin-backport-e39bdc9d in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit e39bdc9d from the openjdk/jdk repository.

The commit being backported was authored by Harold Seigel on 21 Oct 2021 and was reviewed by David Holmes and Coleen Phillimore.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-e39bdc9d:GoeLin-backport-e39bdc9d
$ git checkout GoeLin-backport-e39bdc9d
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-e39bdc9d

Please sign in to comment.