Skip to content

Commit 834e36a

Browse files
committed
Return the default enum if a SecurityException is caught in
getEnumSystemProperty()
1 parent 6e148f5 commit 834e36a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ The <action> type attribute can be add,update,fix,remove.
9898
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix edge-case NullPointerException in org.apache.commons.lang3.SystemUtils.IS_OS_ANDROID.</action>
9999
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix edge-case NullPointerException in org.apache.commons.lang3.SystemUtils.isJavaVersionAtLeast(JavaVersion).</action>
100100
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix edge-case NullPointerException in org.apache.commons.lang3.SystemUtils.isJavaVersionAtMost(JavaVersion).</action>
101+
<action type="fix" dev="ggregory" due-to="Gary Gregory">Return the default enum if a SecurityException is caught in getEnumSystemProperty().</action>
101102
<!-- ADD -->
102103
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Strings and refactor StringUtils.</action>
103104
<action issue="LANG-1747" type="add" dev="ggregory" due-to="Oliver B. Fischer, Gary Gregory">Add StopWatch.run([Failable]Runnable) and get([Failable]Supplier).</action>

src/main/java/org/apache/commons/lang3/EnumUtils.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,18 +309,21 @@ public static <E extends Enum<E>, K> Map<K, E> getEnumMap(final Class<E> enumCla
309309
* <p>
310310
* This method differs from {@link Enum#valueOf} in that it does not throw an exception for an invalid enum name.
311311
* </p>
312+
* <p>
313+
* If a {@link SecurityException} is caught, the return value is {@code null}.
314+
* </p>
312315
*
313-
* @param <E> the type of the enumeration
314-
* @param enumClass the class of the enum to query, not null
315-
* @param propName the system property key for the enum name, null returns default enum
316-
* @param defaultEnum the default enum
317-
* @return the enum, default enum if not found
316+
* @param <E> the type of the enumeration.
317+
* @param enumClass the class of the enum to query, not null.
318+
* @param propName the system property key for the enum name, null returns default enum.
319+
* @param defaultEnum the default enum.
320+
* @return the enum, default enum if not found.
318321
* @since 3.13.0
319322
*/
320323
public static <E extends Enum<E>> E getEnumSystemProperty(final Class<E> enumClass, final String propName,
321324
final E defaultEnum) {
322325
return enumClass == null || propName == null ? defaultEnum
323-
: getEnum(enumClass, System.getProperty(propName), defaultEnum);
326+
: getEnum(enumClass, SystemProperties.getProperty(propName), defaultEnum);
324327
}
325328

326329
/**

0 commit comments

Comments
 (0)