Reputation: 2205
I am debugging into some pretty complex software. Some string is constructed and replaced with a modified form in several different places (the stack is pages long), but I want to find out quickly where the String with a given value is first time constructed. Conditional breakpoints seem to be tricky on this as the condition itself constructs the string I want to detect...
Any ideas? I am using IntelliJ
Upvotes: 3
Views: 289
Reputation: 2664
To avoid creating a new string inside the condition, you can compare the content, not the String objects. For example like this:
Arrays.equals(str.toCharArray(), new char[]{'c', 'o', 'n', 't', 'e', 'n', 't'});
Upvotes: 2
Reputation: 44942
This might not be the easiest approach if your are looking for interned String (e.g. compile time constants) or JVM is performing String de-duplication (G1GC feature).
To make it trickier there were at least two changes in Java 9 that will be hard to breakpoint at:
JEP 280: Indify String Concatenation - InvokeDynamic
makeConcatWithConstants
instead of StringBuilder
when concatenating compile time constants with a +
operator to reduce bytecode (see this article for explanation).
JEP 254: Compact Strings - Latin1 strings stored as byte[]
If you know you are constructing your string with a StringBuilder
I'd place a breakpoint in StringBuilder.toString()
method were the string is hopefully constructed for the first time.
Otherwise good luck debugging through JVM internals e.g. java.lang.invoke.StringConcatFactory
.
Upvotes: 0