Skip to content

Commit

Permalink
[JENKINS-35317] Extra null safety
Browse files Browse the repository at this point in the history
- Should not be needed but just in case the consuming plugin has not used the API correctly (or more probably in the event that a user has managed to partially persist an invalid credential)
  • Loading branch information
stephenc committed Jun 3, 2016
1 parent defdd84 commit 7491bce
Showing 1 changed file with 5 additions and 3 deletions.
Expand Up @@ -28,6 +28,7 @@
import java.text.Collator;
import java.util.Comparator;
import java.util.Locale;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;

Expand Down Expand Up @@ -85,7 +86,8 @@ public CredentialsNameComparator(@CheckForNull Locale locale, boolean ignoreCase
StaplerRequest req = Stapler.getCurrentRequest();
if (req != null) {
locale = req.getLocale();
} else {
}
if (locale == null) {
locale = Locale.getDefault();
}
}
Expand All @@ -98,8 +100,8 @@ public CredentialsNameComparator(@CheckForNull Locale locale, boolean ignoreCase
*/
@Override
public int compare(Credentials c1, Credentials c2) {
final String n1 = CredentialsNameProvider.name(c1);
final String n2 = CredentialsNameProvider.name(c2);
final String n1 = StringUtils.defaultString(CredentialsNameProvider.name(c1));
final String n2 = StringUtils.defaultString(CredentialsNameProvider.name(c2));
if (collator == null) {
// in the event of a race condition this will be effectively idempotent so no need for synchronization.
collator = Collator.getInstance(locale);
Expand Down

0 comments on commit 7491bce

Please sign in to comment.