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.

有帮助吗?

解决方案

Set this setting in your Eclipse,

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top