Modify static variables while debugging in Eclipse

Posted by sleske on Stack Overflow See other posts from Stack Overflow or by sleske
Published on 2010-05-06T09:01:31Z Indexed on 2010/05/06 9:08 UTC
Read the original article Hit count: 316

Filed under:
|
|
|

As an extension the the question "Modify/view static variables while debugging in Eclipse", I'd like to be able to modify static variables while debugging in Eclipse.

For instance and local variables, I can just choose the variable in the "Variables" view of Eclipse, and use the context menu "Change value..." to change the value.

This is not possible for arbitrary static variables, because they do not appear in the "Variables" view.

What I tried:

  1. If you choose "Java / Show static variables" from the triangle menu in the "Variables" view, you can see and modify static member variables of the variables listed in the "Variables view". However, I did not find how to access a static member of a class whose instance does not appear in the "Variables view".
  2. You can of course enter a static member as an expression into the "Expression view" (using fully qualified name). Then you can see the value, but the "Expression view" does not have an option to modify the value (it does allow to modify members of an expression, but not the expression itself, even if the expression is a field).

So, if I have a static variable like a boolean MyClass.disableAllBugs, is there a way to change MyClass.disableAllBugs during debugging?

As an aside: I realize that even having public mutable static fields (i.e. mutable global variables) is very bad style. But some codebases have it, and then it's sometimes useful to modify it while debugging.

© Stack Overflow or respective owner

Related posts about eclipse

Related posts about debugging