Viewing complete strings while debugging in Eclipse

JavaEclipseDebugging

Java Problem Overview


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)

Java Solutions


Solution 1 - Java

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

Solution 2 - Java

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.

Solution 3 - Java

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.

Solution 4 - Java

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

Solution 5 - Java

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

Solution 6 - Java

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.

Solution 7 - Java

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.

Solution 8 - Java

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

Solution 9 - Java

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionragebiswasView Question on Stackoverflow
Solution 1 - JavaEugene KuleshovView Answer on Stackoverflow
Solution 2 - JavaUmbertoView Answer on Stackoverflow
Solution 3 - JavazvikicoView Answer on Stackoverflow
Solution 4 - JavaWaqas AhmedView Answer on Stackoverflow
Solution 5 - JavaSonaliView Answer on Stackoverflow
Solution 6 - JavaPrince ChampappillyView Answer on Stackoverflow
Solution 7 - JavaWesternGunView Answer on Stackoverflow
Solution 8 - Javauser07View Answer on Stackoverflow
Solution 9 - JavaWolfgang FahlView Answer on Stackoverflow