ilkos
ilkos

Reputation: 29

How to change a value while debugging to a variable using a conditional breakpoint in a IntelliJ Kotlin project on the fly?

In an Java Project this is possible while debugging by “mis”-using a conditional breakpoint to set a value to a property or variable:

Java Breakpoint

Unfortunately the same thing is not possible in a Kotlin Project. The error is: Assignments are not expressions, and only expressions are allowed in this context:

Kotlin Breakpoint

I know that I can do it in debugger window using “Set Value”, but then i have to do it every time manually. Using a conditional breakpoint/watchpoint the value is set automatically without even suspending the program until I delete the breakpoint. This is pretty useful for smoke test or presentations.

Thanks in advance!

Upvotes: 2

Views: 1487

Answers (2)

Egor
Egor

Reputation: 2664

Do not do that in the condition field, use "evaluate and log" - this breakpoint action is created specifically for this.

Also you can unset "suspend" and it will silently set value for you:

enter image description here

Upvotes: 2

RobCo
RobCo

Reputation: 6495

You could execute a function to set the value:

run { text = "Some Value" }

This is an expression; it returns Unit, but has the side effect of setting your variable.

If the condition field needs you to return a boolean you can add it after:

run { text = "Some Value"; false }

This returns false so the execution wouldn't stop.

Upvotes: 1

Related Questions