False warnings in IDEA Intellij, what a pain!

I’m a big fan of Eclipse, I’ve been using Visual Age and the very first version of Eclipse. It’s far from perfect but I’ve come to know its weaknesses and became quite efficient.

Every once in a while I take some time to evaluate Intellij IDEA, because, you know, its SOOOOO much better than Eclipse. Not using it only proves you are both stupid and tasteless. That’s what one can hear. I’d love to love this tool but each time I start using it, it looks like he doesn’t like me.

Here is the latest bug I’ve spotted while playing with the otherwise nice code inspection feature.

Let’s say you’ve got this piece of code:

class BugInteger {
    Integer sum(Integer numberOfLongTrades, Integer numberOfShortTrades) {
        return null == numberOfLongTrades ? numberOfShortTrades :
               null == numberOfShortTrades ? numberOfLongTrades :
               (Integer) (numberOfLongTrades + numberOfShortTrades);

    public static void main(String args[]) {
        System.out.println(new BugInteger().sum(1, 2));         // prints 3
        System.out.println(new BugInteger().sum(null, 2));      // prints 2
        System.out.println(new BugInteger().sum(1, null));      // prints 1
        System.out.println(new BugInteger().sum(null, null));   // prints null

IDEA warn me on this code, saying the (Integer) cast is redundant. Looks like it is indeed, so I click on the light bulb to remove the faulty cast. Guess what, my unit tests fails with a NullPointerException.

Looks like the cast was not so redundant! In fact it’s here to protect me from unboxing a null Integer.

This is the typical false warning you’ll get often with IDEA. The kind that makes you disable all the inspections because they are so unreliable. A warning should be an advice you can follow or not, but it should NEVER break the code.

If you think this an isolated bug, then let’s say I’ve seen dozens isolated bugs each time I test IDEA. For now, I’ll keep on testing seriously and will try to post some more positive/negative insights.

3 thoughts on “False warnings in IDEA Intellij, what a pain!”

  1. I discovered IntelliJ a few months ago and I really like it. But I must agree with you about the inspection tool. In IDEA, I never accept an “automatic suggestion” without verifying it.

    For example, I developed a library, where bean setter methods where never call (they had to be called by the library user). IntelliJ suggested me to automatically suppress theses “unused methods”…

    On the other hand, a lot of automatic inspections/resolutions helped me to clean quickly some parts of an old ugly code (if (booleanExpr) {return true;} else {return false;}, etc.)

  2. Hi David,

    Could it be said that your apparently useless cast preventing unboxing null integer is not the most readable piece of code ?

    Maybe, you could consider intellij warning from that point of view. Ok, that is not reliable but I would have done the same misunderstanding. Isn’t it a code smell ? Some smock indicating tricky piece of code that even a computer could fail to analyse ?

    I agree that my comment is a kind of forced objectivity ! From all bad things could come some good (A toutes choses malheur est bon ;-))

Comments are closed.