code: public static Date getDate(JSONObject json, String key, Date defaultValue) {
          Date result = defaultValue;
          if (json.containsKey(key)) {
              try {
                  String secondsString = json.getString(key);
                  //In gerrit, time is written in seconds, not milliseconds.
                  Long milliseconds = TimeUnit.SECONDS.toMillis(Long.parseLong(secondsString));
                  result = new Date(milliseconds);
                  // CS IGNORE EmptyBlockCheck FOR NEXT 2 LINES. REASON: result is already set to defaultValue.
              } catch (JSONException ex) {
              } catch (NumberFormatException nfe) {
              }
          }
          return result;
      }
docs: Returns the value of a JSON property as a Date if it exists otherwise returns the defaultValue.
  @param json the JSONObject to check.
  @param key the key.
  @param defaultValue the value to return if the key is missing.
  @return the value for the key as a Date.