Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 370993 - Debugger calls toString() by itself, changing some variables values.
Summary: Debugger calls toString() by itself, changing some variables values.
Status: CLOSED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 3.8   Edit
Hardware: PC Windows 7
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-08 14:10 EST by Ricardo Ribeiro CLA
Modified: 2012-02-09 11:12 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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