Community
Participate
Working Groups
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.
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