Repository: jenkinsci/jenkins
File: core/src/main/java/jenkins/util/SystemProperties.java (Java)

Code before:
     * @return the property value as a duration.
     * @since TODO
     */
    @Nullable
    public static Duration getDuration(@NonNull String name, @CheckForNull Duration defaultValue, @NonNull Level logLevel) {
        return getDuration(name, null, defaultValue, logLevel);
    }

    /**
     * Determines the duration value of the system property with the specified name, or a default value.
     *
     * @param name         property name.
     * @param unit         the duration unit to use if the value doesn't specify one (defaults to `ms`)
     * @param defaultValue a default value
     * @param logLevel     the level of the log if the provided system property name cannot be parsed into Duration.
     * @return the property value as a duration.
     * @since TODO
     */
    @Nullable
    public static Duration getDuration(@NonNull String name, @CheckForNull ChronoUnit unit, @CheckForNull Duration defaultValue, @NonNull Level logLevel) {
        String v = getString(name);
        if (v != null) {
            try {
                return DurationStyle.detectAndParse(v, unit);
            } catch (Exception e) {
                LOGGER.log(logLevel, e, () -> "Property. Value is not a duration: " + name + " => " + v);
            }
        }
        return defaultValue;
    }

    /**
      * Determines the integer value of the system property with the
      * specified name.
      *
      * This behaves just like {@link Integer#getInteger(java.lang.String)}, except that it
      * also consults the {@link ServletContext}'s "init" parameters.
      *
      * @param   name property name.
      * @return  the {@code Integer} value of the property.
      */
    @CheckForNull
    public static Integer getInteger(String name) {
        return getInteger(name, null);
    }

    /**
     * Determines the integer value of the system property with the
     * specified name, or a default value.
     *
     * This behaves just like {@code Integer.getInteger(String,Integer)}, except that it

Review comment (bug):
this may be better:
```suggestion
                LOGGER.log(logLevel, e, () -> "Failed to convert %s to a valid duration for property %s, falling back to default %s".formatted(v, name, defaultValue));
```

Code after:
        return defaultValue;
    }

    /**
      * Determines the integer value of the system property with the
      * specified name.
      *
      * This behaves just like {@link Integer#getInteger(java.lang.String)}, except that it
      * also consults the {@link ServletContext}'s "init" parameters.
      *
      * @param   name property name.
      * @return  the {@code Integer} value of the property.
      */
    @CheckForNull
    public static Integer getInteger(String name) {
        return getInteger(name, null);
    }

    /**
     * Determines the integer value of the system property with the
     * specified name, or a default value.
     *
     * This behaves just like {@code Integer.getInteger(String,Integer)}, except that it
     * also consults the {@code ServletContext}'s "init" parameters. If neither exist,
     * return the default value.
     *
     * @param   name property name.
     * @param   def   a default value.
     * @return  the {@code Integer} value of the property.
     *          If the property is missing, return the default value.
     *          Result may be {@code null} only if the default value is {@code null}.
     */
    public static Integer getInteger(String name, Integer def) {
        return getInteger(name, def, Level.CONFIG);
    }

    /**
      * Determines the integer value of the system property with the
      * specified name, or a default value.
      *
      * This behaves just like {@code Integer.getInteger(String,Integer)}, except that it
      * also consults the {@code ServletContext}'s "init" parameters. If neither exist,
      * return the default value.
      *
      * @param   name property name.
      * @param   def   a default value.
      * @param   logLevel the level of the log if the provided system property name cannot be decoded into Integer.
      * @return  the {@code Integer} value of the property.
      *          If the property is missing, return the default value.
      *          Result may be {@code null} only if the default value is {@code null}.
      */