Search code examples
javaandroidandroid-studioassertandroid-studio-3.1

Android Studio assert not working


I'm calling findViewById and Android Studio (version 3.1, stable) prompts me to put an assertion:

enter image description here

When I select it, it adds the following line above the selected line:

assert v != null;

Great. I run the app, and the View v is null. However, assertion doesn't work and it jumps to the line below it in debugger:

enter image description here

How is this even possible? It was Android Studio's own suggestion, and I didn't change a thing. Its own recommendation/autogenerated code is not working. Am I missing something obvious?


Solution

  • Apparently, (as stated in the comments) assertions are disabled by default but encouraged by Android Studio.

    In this manner, the "problem" can be classified as a misleading UX issue rather than a technical problem.