Skip to content

Commit a289e4e

Browse files
More flexible APIs. support null and empty strings
1 parent e4d064b commit a289e4e

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/main/java/com/cloudbees/syslog/Facility.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ public static Facility fromNumericalCode(int numericalCode) throws IllegalArgume
168168
}
169169

170170
/**
171-
* @param label Syslog facility textual code
171+
* @param label Syslog facility textual code. {@code null} or empty returns {@code null}
172172
* @return Syslog facility, {@code null} if given value is {@code null}
173173
* @throws IllegalArgumentException the given value is not a valid Syslog facility textual code
174174
*/
175175
@Nullable
176176
public static Facility fromLabel(String label) throws IllegalArgumentException {
177-
if (label == null)
177+
if (label == null || label.isEmpty())
178178
return null;
179179

180180
Facility facility = facilityFromLabel.get(label);

src/main/java/com/cloudbees/syslog/Severity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ public static Severity fromNumericalCode(int numericalCode) throws IllegalArgume
9494
}
9595

9696
/**
97-
* @param label Syslog severity textual code
97+
* @param label Syslog severity textual code. {@code null} or empty returns {@code null}
9898
* @return Syslog severity, {@code null} if given value is {@code null}
9999
* @throws IllegalArgumentException the given value is not a valid Syslog severity textual code
100100
*/
101101
@Nullable
102102
public static Severity fromLabel(@Nullable String label) throws IllegalArgumentException {
103-
if (label == null)
103+
if (label == null || label.isEmpty())
104104
return null;
105105

106106
Severity severity = severityFromLabel.get(label);

src/main/java/com/cloudbees/syslog/integration/jul/util/LevelHelper.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ public class LevelHelper {
6868
/**
6969
* Simplification: use delegate to {@link Level#parse(String)} even if the behavior is slightly different for localized log levels.
7070
*
71-
* @param name
71+
* @param name {@code null} or empty returns {@code null}
7272
* @return
7373
*/
7474
@Nullable
75-
public static Level findLevel(@Nonnull String name) {
75+
public static Level findLevel(@Nullable String name) {
76+
if(name == null || name.isEmpty())
77+
return null;
7678
return Level.parse(name);
7779

7880
}

0 commit comments

Comments
 (0)