175
votes

While debugging Java code, Strings in the views "Variables" and "Expressions" show up only till a certain length, after which Eclipse shows "..."

Is there any way to inspect the entire string? (This eases the pain of adding logging statements for debugging everywhere)

9
where are you seeing this behaviour? which part of the debugger? - skaffman
On a side note, this might be a misnomer, because it might not work for you, but if you use a debugging library like java.util.logging or log4j, you can easily turn your debug statements (with different levels of debugging) into printouts or to logfiles and it may give you the edge that sifting through strings in the debug window might not. Just a thought =) - corsiKa

9 Answers

240
votes

In the Variables view you can right click on Details pane (the section where the string content is displayed) and select "Max Length..." popup menu. The same length applies to expression inspector popup and few other places.

enter image description here

134
votes

In the Variables view you right-click on the variable and select Change value. If your variable is huge you have to wait a few minutes (in this case Eclipse doesn't respond to commands) but in the end Eclipse will show your variable entirely.

22
votes

If you have a really long string, I use a different strategy: dump it to a file. I have a snippet of code I use in the Display view, which is evaluated to dump the data to a file. I use Commons IO, but you can do it with JDK only methods.

org.apache.commons.io.FileUtils.writeStringToFile(new java.io.File("<filename>"), <expression to evaluate>);

Naturally, you will need the Commons IO JAR in your classpath for that to work. If you don't, resort to JDK work.

19
votes

The best way to view a String value from eclipse debug view is as below.

1) Switch to debug view in Eclipse

2) Select the desired variable in variable pane.

3) Right click on display area of variable pane where value is shown and click on Max Length. Enter the maximum char value in Configure Details Pane .

4) Cheers

enter image description here

3
votes

When debugger reaches the point where you want the String value, just type a sysOut statement

System.out.println("The value is : \n " + query);

Select the above the statement, right click-> Execute

It will print the value on the console

0
votes

For javascript based debugging on eclipse, "change value" method and "Max length" method both failed for me, adding the required object to watch(Expressions) and then Right Clicking the watched expression to select "Load Full Value" is the only solution that works for me, but even this inserts unwanted "\n" in the output.

Note - "Max length" must be set for the "Load Full Value" to work as it loads values till max length(default in eclipse is 10000). Refer above answer to see how to set Max length.

0
votes

There is no "maxLength" in Eclipse Mars. And, the "change value" only works with "Variables", not "Expressions", so none of above works for me.

enter image description here

And, the expression are cut in the middle, not at the end. I guess they changed the default behaviour.

The only thing working for me, is to expand the expression name column's width, and click the expression to select it all to see the full length content.

0
votes

Nothing from the above worked for me, moreover, some user interface elements in my Eclipse can not be found as described. I'm using STS 4.3.1.

The value I needed was really big, it is part of a huge JSON request. Workaround is to use an expression in Eclipse Debug Shell console and to output the substring of the whole value. Since you can see the partial value, inspect it and use the last few literals as the position to output the next chunk of the string. Repeat this approach until get what you need:

String result = new String(reallyBigByteArrayValue, "UTF-8");
result.substring(result.indexOf("some-unique-text"));
0
votes

In Eclipse IDE 2020-09 it's "Pretty print to console" on right click. Right Click dialog

From the console the copying is possible at full length.