SimplifiedTernary: Incorrect ternary operation can be simplified Maven PMD

When checking the quality of the code, you may encounter a problem that sounds like this:

SimplifiedTernary: Incorrect ternary operation can be simplified

Or like this:

Ternary operators that can be simplified with || or &&

This is not a bug in PMD. Here are some examples:

// This line
setValue(varOfBooleanClass != null ? varOfBooleanClass : false);
// Can be simplified to
setValue(varOfBooleanClass != null && varOfBooleanClass);

// And this line
setValue(cacheBlocks == null ? true : cacheBlocks);
// Can be simplified to
setValue(cacheBlocks == null || cacheBlocks);
Telegram channel

If you still have any questions, feel free to ask me in the comments under this article or write me at promark33@gmail.com.

If I saved your day, you can support me 🤝

Leave a Reply

Your email address will not be published. Required fields are marked *