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

Cleanup unnecessary null comparison before instanceof check in java.base

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 17
    • Component/s: core-libs
    • Labels:
    • Resolved In Build:
      b05

      Description

      Update code checks both non-null and instance of a class in java.base module classes.
      The checks and explicit casts could also be replaced with pattern matching for the instanceof operator.
      For example:
          The following code:
              if ((obj != null) && (obj instanceof File)) {
                  return compareTo((File)obj) == 0;
          Can be simplified to:
              if (obj instanceof File file) {
                  return compareTo(file) == 0;

      The initial patch was proposed by Andrey Turbanov(turbanoff):
      https://github.com/openjdk/jdk/pull/20

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              aefimov Aleksej Efimov
              Reporter:
              aefimov Aleksej Efimov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: