RFR: JDK-8297413: Remove easy warnings in javafx.graphics

John Hendrikx jhendrikx at openjdk.org
Wed Nov 23 08:05:30 UTC 2022


On Tue, 22 Nov 2022 18:39:43 GMT, John Hendrikx <jhendrikx at openjdk.org> wrote:

> - Remove unsupported/unnecessary SuppressWarning annotations
> - Remove reduntant type specifications (use diamond operator)
> - Remove unused or duplicate imports
> - Remove unnecessary casts (type is already correct type or can be autoboxed)
> - Remove unnecessary semi-colons (at end of class definitions, or just repeated ones)
> - Remove redundant super interfaces (interface that is already inherited)
> - Remove unused type parameters
> - Remove declared checked exceptions that are never thrown
> - Add missing `@Override` annotations

It's clear that the unnecessary cast removal is causing many discussions, so I think its best to back out that change. The danger in many unnecessary casts is that they can become **real** casts after a seemingly innocuous change, so it is mostly a benefit to make refactors easier to reason about.  Unnecessary casts turning into down casts are the ones that will cause trouble:

        float x, y, z;
        float a = (float)x * (float)y * (float)z;   // unnecessary casts

However, after a refactor:

        double x, y, z;
        float a = (float)x * (float)y * (float)z;   // down casts (no warning!)

The extra precision that one may have hoped to gain is still lost.

Similarly:

        Integer number = ... ;
        Integer x = (Integer) number;  // unnecessary cast

Refactor:

        Number number = ... ;
        Integer x = (Integer) number;  // down cast (no warning!)

The code may now raise a `ClassCastException` here if `Number` is not an `Integer`. Without the unnecessary cast this would be a compile error to be investigated.

-------------

PR: https://git.openjdk.org/jfx/pull/960


More information about the openjfx-dev mailing list