skip to Main Content

Since Android Studio Electric Eel, I encountered this pretty dangerous bug a few times, when running the debug version of the app..

As you can see (sorry for the censored code), at line 2, while I’m in debug, the IF condition should fail as the first value is false….

"Model.skipCheck" at line 2 is a read-only property of the object Model that I use to skip some checks if I’m running the debug version of the app.

I think the IDE here, when building the debug version, is caching that property, as I usually run the app with that property at true.

enter image description here

Usually I fix this issue making a small, irrelevant change to that line, so perhaps the compiler compiles again that portion of code and then it works correctly..

But this kind of issue should never occur, as it can be very dangerous and hard to spot.
Have you ever encountered this issue? Is it a know bug? Is there any way of preventing this behaviour?

I’m running Android Studio Flamingo | 2022.2.1

Edit:

object Model {
    const val skipCheck = false
    var preventLogin = false
    var blacklisted: List<User>? = null
}

2

Answers


  1. Chosen as BEST ANSWER

    Turns out there is an issue with parallel runs..

    Unchecking Edit Configurations -> [modulename] -> "Allow parallel run" solved my problem


  2. I just had the same bug which was hard to reproduce. And it occurred that it was multi-threading issue. My variable was updated from another thread and that’s why I got the wrong behaviour.

    Android Studio doesn’t manage the objects and variables, because all objects & primitives are stored in Heap & Stack memory of JVM.

    So the only advice I can give you is to put a breakpoint to the setter method of Model.variable in order to figure out, how and when the false value is being set to this variable.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search