Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8073479

Replace obj.getClass hacks with Objects.requireNonNull

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None
    • Resolved In Build:
      b53

      Backports

        Description

        A few places in our class library use the weird trick of using object.getClass() to check for nullity.
        While this make seem a smart move, it actually confuses people into believing this is an approved
        practice of null checking.

        With JDK 7, we have Objects.requireNonNull that provide the proper null checking, and declare the
        intent properly. There is no performance implications of using it instead of getClass():
          http://cr.openjdk.java.net/~shade/scratch/NullChecks.java

        (Actually, there *are* a few stubborn corner cases with performance implications; see JDK-8042127.)

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                shade Aleksey Shipilev
                Reporter:
                shade Aleksey Shipilev
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: