Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify static variables while debugging in Eclipse

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.

like image 985
sleske Avatar asked May 06 '10 09:05

sleske


1 Answers

You can write a temporary line SomeClass.myStaticVar = newValue;, select it, right-click and "execute" it.

like image 128
Bozho Avatar answered Oct 23 '22 03:10

Bozho