Follow

Just found a
if(value == null && value != null)
in Code that passed my review πŸ™ˆπŸ™ˆπŸ™ˆ

Β· Tusky Β· 9 Β· 1 Β· 13

@ConnyDuck
I'm curious what the unreachable code is...
I hope it's a joke of some sort. That would mean the person who wrote it knew what they were doing, rather than having a massive brain-fart.

@kd0bpv it happened during a Java -> Kotlin refactor where Optionals were removed. Previously it read
if(optional != null && !optional.isPresent())

@ConnyDuck maybe it is Schrodinger's value and null and not null at the same time.

@ConnyDuck Someone semi-recently found this in code that I wrote, which passed review by multiple people.

if(condition);
doThing();

Fortunately, the condition was almost always true in normal circumstances, so the behavior was still as intended.
Unfortunately, the condition was almost always true in normal circumstances, so it took quite a while for the mistake to be found.

@charlag I simplified it, it was done with isNull extension functions and thats apparently not caught by inspections

@ConnyDuck You never know. The value of _value_ might change between those evaluations. ^^

Sign in to participate in the conversation
Mastodon

Follow friends and discover new ones. Publish anything you want: links, pictures, text, video. This server is run by the main developers of the Mastodon project. Everyone is welcome as long as you follow our code of conduct!