Some not-so-careful colleagues of mine have been passing around Optional
instances and assuming it's safe to call get
on them without calling isPresent
first.
I know... this shouldn't happen, but the type-system won't stop them!!
So, I wanted IntelliJ to do it. Is it possible to configure IntelliJ so that it will warn (or even throw a compiling error) about calling Optional.get()
without first calling Optional.isPresent()
?
IntelliJ 2016.1 supports this out-of-the-box!
By default, calling get()
without verifying with isPresent()
first will issue a warning, but you can go to the "Inspections" screen and set Optiong.get() without isPresent() check
to have severity "Error" if you prefer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With