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

Unnecessary NullPointerException catch in java.util.TimeZone#setDefaultZone

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 21
    • None
    • core-libs

      Method java.util.TimeZone#setDefaultZone has catch for NullPointerException:

              // if the time zone ID is not set (yet), perform the
              // platform to Java time zone ID mapping.
              if (zoneID == null || zoneID.isEmpty()) {
                  String javaHome = StaticProperty.javaHome();
                  try {
                      zoneID = getSystemTimeZoneID(javaHome);
                      if (zoneID == null) {
                          zoneID = GMT_ID;
                      }
                  } catch (NullPointerException e) {
                      zoneID = GMT_ID;
                  }
              }

      But NPE couldn't happen in try block. We can remove catch block to simplify code a bit.

            jlu Justin Lu
            aturbanov Andrey Turbanov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: