Question

I would like to generate warnings for ALL autoboxing and unboxing.

Has anyone found an effective way?

Eclipse catches basic autoboxing errors: eg. Integer i = null; i++. But fails on anything complex, and isn't really what I'm after.

I've looked at PMD and Checkstyle but couldn't find anything there.

I know it's a controversial subject, but I think it's a dangerous feature. There's no way to disable it, so I would at least like a report to check during code reviews.

I see this NullPointerException far too often in code reviews and bugs:

class X {
    Integer i = null;

    public int doSomething() {
        return i + 2;
    }
}

I want to stop it from getting that far.

Was it helpful?

Solution

Set this setting in your Eclipse,

Preferences -> Java -> Compiler -> Errors/Warnings -> Potential Programming Problems -> Boxing and unboxing conversions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top