Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.lang.ref.WeakReference;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -73,7 +74,18 @@
*/
public final class ShortenedStrings {

private static final Map<String, StringInfo> infoStrings = new WeakHashMap<String, StringInfo>();
/**
* Shortened display text → full remote content helper.
* <p>
* Must be a strong map for the duration of a debugger session. A
* {@link WeakHashMap} drops the entry as soon as nothing holds the exact
* key {@link String} instance. The UI / property editor often holds an
* equal but different instance (or a quoted form from
* {@code Variable.getValue()}), so lookup fails while the truncated
* preview is still shown and "Save Value to File" only writes that
* preview. Cleared when the last debugger session ends.
*/
private static final Map<String, StringInfo> infoStrings = new HashMap<String, StringInfo>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason to switch from WeakHashMap to HashMap. The full strings are looked up by a string and if the key goes out of scope it makes sense, that the referenced value is removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matthiasblaesing the WeakHashMap key is the shortened display string. Lookup often uses a different String instance (or a quoted Variable.getValue() form), so the entry can disappear while the UI still shows the truncated value and Save only writes that preview.

HashMap keeps it for the session; we still clear on last session remove. Also added quoted-form lookup.

private static final Map<StringReference, StringValueInfo> stringsCache = new WeakHashMap<StringReference, StringValueInfo>();
private static final Set<StringReference> retrievingStrings = new HashSet<StringReference>();
private static final Map<VirtualMachine, Boolean> isLittleEndianCache =
Expand All @@ -85,7 +97,7 @@ public final class ShortenedStrings {

@Override
public void sessionRemoved(Session session) {
// Clean up. WeakHashMap does not clean up if not touched. :-(
// Strong infoStrings map is session-scoped; clear when idle.
int n = DebuggerManager.getDebuggerManager().getSessions().length;
if (n == 0) {
synchronized (infoStrings) {
Expand All @@ -107,8 +119,19 @@ public void sessionRemoved(Session session) {
private ShortenedStrings() {}

public static StringInfo getShortenedInfo(String s) {
if (s == null) {
return null;
}
synchronized (infoStrings) {
return infoStrings.get(s);
StringInfo info = infoStrings.get(s);
if (info != null) {
return info;
}
// Variable.getValue() wraps Strings in quotes: "content..."
if (s.length() >= 2 && s.charAt(0) == '"' && s.charAt(s.length() - 1) == '"') {
return infoStrings.get(s.substring(1, s.length() - 1));
}
return null;
}
}

Expand Down