From 8dd76834b638c735cb06f6f025f6308e06934e84 Mon Sep 17 00:00:00 2001 From: Alex Macdonald Date: Fri, 1 Dec 2023 21:18:59 +0000 Subject: [PATCH] 4262: Duplicate headers when copying thread dump text to clipboard Reviewed-by: hirt --- .../ui/pages/ThreadDumpsPage.java | 31 ++++--------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/pages/ThreadDumpsPage.java b/application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/pages/ThreadDumpsPage.java index dc7579b6c7..07f5034fbf 100644 --- a/application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/pages/ThreadDumpsPage.java +++ b/application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/pages/ThreadDumpsPage.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -39,7 +39,6 @@ import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; -import java.util.stream.Stream; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.resource.ImageDescriptor; @@ -154,11 +153,9 @@ public int hashCode() { } private static class ThreadDump extends Node { - final ThreadDumpCollection parent; - ThreadDump(String title, String body, ThreadDumpCollection parent) { + ThreadDump(String title, String body) { super(title, body); - this.parent = parent; } } @@ -403,23 +400,7 @@ private static String joinSelection(List selection) { } private static String joinSelectionForCopy(IStructuredSelection selection) { - List list = selection.toList(); - @SuppressWarnings("unchecked") - Set parents = (Set) list.stream() - .filter(o -> o instanceof ThreadDumpCollection).collect(Collectors.toSet()); - return list.stream() - .flatMap(o -> o instanceof ThreadDumpCollection - ? getThreadDumpCollectionStreamForCopy((ThreadDumpCollection) o) - : getThreadDumpStreamForCopy(parents, (ThreadDump) o)) - .map(n -> n.body).collect(Collectors.joining(SEPARATOR)); - } - - private static Stream getThreadDumpCollectionStreamForCopy(ThreadDumpCollection tdc) { - return Stream.concat(Stream.of(tdc), Stream.of((tdc.dumps))); - } - - private static Stream getThreadDumpStreamForCopy(Set parents, ThreadDump td) { - return parents.contains(td.parent) ? Stream.empty() : Stream.concat(Stream.of(td.parent), Stream.of(td)); + return joinSelection(selection.toList()); } private static ThreadDumpCollection[] parseEvents(IItemIterable is) { @@ -436,7 +417,7 @@ private static ThreadDumpCollection parseCollection(String title, String str) { ThreadDump[] dumps = new ThreadDump[parts.length - 2]; ThreadDumpCollection parent = new ThreadDumpCollection(title, str, dumps); for (int i = 0; i < dumps.length; i++) { - dumps[i] = parseThreadDump(parts[i + 1], parent); + dumps[i] = parseThreadDump(parts[i + 1]); } return parent; } else { @@ -444,11 +425,11 @@ private static ThreadDumpCollection parseCollection(String title, String str) { } } - private static ThreadDump parseThreadDump(String str, ThreadDumpCollection parent) { + private static ThreadDump parseThreadDump(String str) { str = str.trim(); int firstLineEnd = str.indexOf('\n'); String firstLine = firstLineEnd < 0 ? str : str.substring(0, firstLineEnd); int lastQuote = firstLine.lastIndexOf('"'); - return new ThreadDump(lastQuote > 1 ? firstLine.substring(1, lastQuote) : firstLine, str, parent); + return new ThreadDump(lastQuote > 1 ? firstLine.substring(1, lastQuote) : firstLine, str); } }