Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate warnings for autoboxing use

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.

like image 757
David Lavender Avatar asked Feb 22 '13 09:02

David Lavender


1 Answers

Set this setting in your Eclipse,

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

like image 141
Jayamohan Avatar answered Oct 26 '22 06:10

Jayamohan