Skip to content

Commit

Permalink
4262: Duplicate headers when copying thread dump text to clipboard
Browse files Browse the repository at this point in the history
Reviewed-by: hirt
  • Loading branch information
aptmac committed Dec 1, 2023
1 parent fea5d67 commit 8dd7683
Showing 1 changed file with 6 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

}
Expand Down Expand Up @@ -403,23 +400,7 @@ private static String joinSelection(List<?> selection) {
}

private static String joinSelectionForCopy(IStructuredSelection selection) {
List<?> list = selection.toList();
@SuppressWarnings("unchecked")
Set<ThreadDumpCollection> parents = (Set<ThreadDumpCollection>) 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<Node> getThreadDumpCollectionStreamForCopy(ThreadDumpCollection tdc) {
return Stream.concat(Stream.of(tdc), Stream.of((tdc.dumps)));
}

private static Stream<Node> getThreadDumpStreamForCopy(Set<ThreadDumpCollection> 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) {
Expand All @@ -436,19 +417,19 @@ 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 {
return new ThreadDumpCollection(title, str, new ThreadDump[0]);
}
}

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);
}
}

0 comments on commit 8dd7683

Please sign in to comment.