Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 370993

Summary: Debugger calls toString() by itself, changing some variables values.
Product: [Eclipse Project] JDT Reporter: Ricardo Ribeiro <cardao916>
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: CLOSED INVALID QA Contact:
Severity: minor    
Priority: P3 CC: Michael_Rennie, remy.suen
Version: 3.8   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Ricardo Ribeiro CLA 2012-02-08 14:10:14 EST
Build Identifier: M20100909-0800

If a toString() implementation changes a value of a variable inside a class, hovering the mouse over an object that implements such toString() make the value change, because the debbuger, not the code, has called toString(), producing unexpected results within the debug view.

It's a minor thing ocurring only when toString() is implemented in a non recommended way. But maybe the debbuger could call toString() on a copy of the object the mouse is hovering, not the original object.

Reproducible: Always

Steps to Reproduce:
1. Implement a toString() with value atribution to some variable.
2. Start debug on some program.
3. Hover the mouse over an object with the given toString() implementation.
Comment 1 Michael Rennie CLA 2012-02-09 11:12:20 EST
If a user overrides toString that is their choice - the debugger makes the standard call to toString to display object information (if no detail formatters are provided).

The idea of cloning objects to avoid something like this would have a very negative impact on performance and memory usage of the debugger. Luckily though there are two things you can do to work around this:

1. don't implement toString to modify your class
2. provide a detail formatter for the details pane, see: http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.jdt.doc.user/reference/preferences/java/debug/ref-detail_formatters.htm