r/programminghumor • • 7d ago

Java

Post image
1.4k Upvotes

27 comments sorted by

View all comments

76

u/Ignisami 7d ago edited 7d ago

You're missing

if (Boolean.TRUE.equals(condition)) which is what SonarQube's default Java rules will recommend. (edit: in case anyone wonders, it's because of null safety; if (condition) throws an NPE if condition is null, Boolean.TRUE.equals(condition) just evaluates to false)

39

u/NoWeHaveYesBananas 7d ago

What if you want it to throw an error, and not hide your bugs like a coward

23

u/vanteli 7d ago

you tighten your pussy like a man and assert condition != null;

20

u/Ignisami 7d ago
try {
if (condition) { /* code whatever */ }
} catch (MommaAintRaisedNoCowardException _) {
log.error("No bugs to be seen here no sirreee");
}

public class MommaAintRaisedNoCowardException  
 extends NullPointerException   
{ /* standard exception stuff */ }