Skip to content

Commit 7c0f013

Browse files
committedSep 9, 2024
8339488: Extended NPE message doesn't handle CONSTANT_Dynamic
Reviewed-by: lmesnik, coleenp, simonis, liach
1 parent d53e405 commit 7c0f013

File tree

3 files changed

+99
-1
lines changed

3 files changed

+99
-1
lines changed
 

‎src/hotspot/share/interpreter/bytecodeUtils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ int ExceptionMessageBuilder::do_instruction(int bci) {
643643
}
644644
}
645645

646-
constantTag tag = cp->tag_at(cp_index);
646+
constantTag tag = cp->constant_tag_at(cp_index);
647647
if (tag.is_klass() || tag.is_unresolved_klass() ||
648648
tag.is_method() || tag.is_interface_method() ||
649649
tag.is_field() || tag.is_string()) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2024, 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+
* This test generates an extended NullPointerException inside a method with
26+
* a condy ldc. We add two ldc instructions and a pop around the real null
27+
* value to stress the stack handling of the NPE message generator.
28+
*/
29+
class CondyExtendedNullPointer
30+
version 55:0
31+
{
32+
33+
static Field nullObject:"Ljava/lang/Object;";
34+
35+
public static Method condy:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)I"
36+
stack 1 locals 3
37+
{
38+
bipush 123;
39+
ireturn;
40+
}
41+
42+
public static Method main:"([Ljava/lang/String;)V"
43+
stack 3 locals 1
44+
{
45+
ldc Dynamic REF_invokeStatic:CondyExtendedNullPointer.condy:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)I":I:"I";
46+
getstatic Field nullObject:"Ljava/lang/Object;";
47+
ldc Dynamic REF_invokeStatic:CondyExtendedNullPointer.condy:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)I":I:"I";
48+
pop;
49+
invokevirtual Method java/lang/Object.notify:"()V";
50+
return;
51+
}
52+
53+
} // end Class CondyExtendedNullPointer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2024, 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 8339488
27+
* @summary Test extended NullPointerException message in method with CONSTANT_Dynamic.
28+
* @modules java.base/jdk.internal.misc
29+
* @library /test/lib
30+
* @compile CondyExtendedNullPointer.jasm
31+
* @run driver CondyExtendedNullPointerTest
32+
*/
33+
34+
import jdk.test.lib.process.ProcessTools;
35+
import jdk.test.lib.process.OutputAnalyzer;
36+
37+
public class CondyExtendedNullPointerTest {
38+
public static void main(String args[]) throws Throwable {
39+
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder("-Xverify:all",
40+
"CondyExtendedNullPointer");
41+
OutputAnalyzer oa = new OutputAnalyzer(pb.start());
42+
oa.shouldContain("Cannot invoke \"Object.notify()\" because \"CondyExtendedNullPointer.nullObject\" is null");
43+
oa.shouldHaveExitValue(1);
44+
}
45+
}

0 commit comments

Comments
 (0)