Skip to content

Commit e2287af

Browse files
committed
8216977: ShowHiddenFrames use in java_lang_StackTraceElement::fill_in appears broken
Return NULL source file and negative line number for hidden frames. Reviewed-by: dholmes, hseigel
1 parent bcff499 commit e2287af

File tree

3 files changed

+81
-12
lines changed

3 files changed

+81
-12
lines changed

src/hotspot/share/classfile/javaClasses.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,10 +2594,6 @@ void java_lang_StackTraceElement::fill_in(Handle element,
25942594
source_file = NULL;
25952595
java_lang_Class::set_source_file(java_class(), source_file);
25962596
}
2597-
if (ShowHiddenFrames) {
2598-
source = vmSymbols::unknown_class_name();
2599-
source_file = StringTable::intern(source, CHECK);
2600-
}
26012597
}
26022598
java_lang_StackTraceElement::set_fileName(element(), source_file);
26032599

@@ -2635,11 +2631,7 @@ void java_lang_StackTraceElement::decode(Handle mirror, int method_id, int versi
26352631
// via the previous versions list.
26362632
holder = holder->get_klass_version(version);
26372633
assert(holder != NULL, "sanity check");
2638-
Symbol* source = holder->source_file_name();
2639-
if (ShowHiddenFrames && source == NULL) {
2640-
source = vmSymbols::unknown_class_name();
2641-
}
2642-
filename = source;
2634+
filename = holder->source_file_name();
26432635
line_number = Backtrace::get_line_number(method, bci);
26442636
}
26452637
}

src/hotspot/share/classfile/javaClasses.inline.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,6 @@ inline int Backtrace::get_line_number(const methodHandle& method, int bci) {
274274
} else {
275275
// Returns -1 if no LineNumberTable, and otherwise actual line number
276276
line_number = method->line_number_from_bci(bci);
277-
if (line_number == -1 && ShowHiddenFrames) {
278-
line_number = bci + 1000000;
279-
}
280277
}
281278
return line_number;
282279
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 2019, 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 8216977
27+
* @summary Test null source file and negative line number from hidden frame produces correct output.
28+
* @library /test/lib
29+
* @run main/othervm -XX:+ShowHiddenFrames HiddenFrameTest visible
30+
* @run main/othervm -XX:-ShowHiddenFrames HiddenFrameTest hidden
31+
*/
32+
33+
import jdk.test.lib.Asserts;
34+
35+
public class HiddenFrameTest {
36+
37+
@FunctionalInterface
38+
private static interface SomeFunctionalInterface {
39+
String someMethod(String a, String b);
40+
}
41+
42+
static void assertContains(String expected, String actual, Exception e, boolean framesAreHidden) throws Exception {
43+
if (!framesAreHidden && !actual.contains(expected)) {
44+
throw new RuntimeException("Expected: " + expected + "; Actual: " + actual, e);
45+
} else if (framesAreHidden && actual.contains(expected)) {
46+
throw new RuntimeException("Unexpected: " + expected + "; Actual: " + actual, e);
47+
}
48+
}
49+
50+
static void checkException(Exception e, boolean framesAreHidden) throws Exception {
51+
StackTraceElement[] fs = e.getStackTrace();
52+
53+
if (fs.length < 2) {
54+
throw new RuntimeException("Exception should have at least two frames", e);
55+
}
56+
57+
assertContains("someMethod(Unknown Source)", fs[0].toString(), e, framesAreHidden);
58+
}
59+
60+
public static void main(String[] args) throws Exception {
61+
boolean framesAreHidden = false;
62+
if (args.length > 0) {
63+
String arg = args[0];
64+
if (arg.equals("hidden")) framesAreHidden = true;
65+
}
66+
67+
try {
68+
final SomeFunctionalInterface concatter = String::concat;
69+
final String nullString = null;
70+
if (concatter != null) {
71+
// This throws NPE from the lambda expression which is a hidden frame
72+
concatter.someMethod(nullString, "validString");
73+
}
74+
} catch (NullPointerException e) {
75+
e.printStackTrace();
76+
checkException(e, framesAreHidden);
77+
}
78+
}
79+
}
80+

0 commit comments

Comments
 (0)