/* * Copyright (c) 2015, 2022, 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.
*/
privatestatic Logger logger = Logger.getLogger("stackstream"); public StackStreamTest() {
}
publicvoid test() {
A.a();
} staticclass A { publicstaticvoid a() {
B.b();
}
} staticclass B { publicstaticvoid b() {
C.c();
}
} staticclass C { publicstaticvoid c() {
D.d();
}
} staticclass D { publicstaticvoid d() {
E.e();
}
} staticclass E { publicstaticvoid e() {
F.f();
}
} staticclass F { publicstaticvoid f() {
logger.severe("log message");
G.g(); new K().k();
}
}
privatestaticboolean isTestClass(StackFrame f) { // Filter jtreg frames from the end of the stack return f.getClassName().startsWith("StackStreamTest");
}
// Do we need this?
System.out.println("Collect StackTraceElement");
List<StackTraceElement> stacktrace = STE_WALKER.walk(s ->
{ // Filter out jtreg frames return s.filter(StackStreamTest::isTestClass)
.collect(Collectors.mapping(StackFrame::toStackTraceElement, Collectors.toList()));
}); int i=0; for (StackTraceElement s : stacktrace) {
System.out.format(" %d: %s%n", i++, s);
}
// Check STEs for correctness
checkStackTraceElements(GOLDEN_CLASS_NAMES, GOLDEN_METHOD_NAMES, stacktrace);
}
staticvoid checkStackTraceElements(List<String> classNames,
List<String> methodNames,
List<StackTraceElement> stes) { if (classNames.size() != methodNames.size() ) { thrownew RuntimeException("Test error: classNames and methodNames should be same size");
} if (classNames.size() != stes.size()) {
dumpSTEInfo(classNames, methodNames, stes); thrownew RuntimeException("wrong number of elements in stes");
} for (int i = 0; i < classNames.size() ; i++) { if (!classNames.get(i).equals(stes.get(i).getClassName()) ||
!methodNames.get(i).equals(stes.get(i).getMethodName())) {
dumpSTEInfo(classNames, methodNames, stes); thrownew RuntimeException("class & method names don't match");
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.