Skip to content
Permalink
Browse files

[FIXED JENKINS-38721, JENKINS-37282] - NPE in "CauseOfInterruption.Us…

…erInterruption" when user is missing (#2630)

* [FIXED JENKINS-38721] - Prevent NPE during rendering of "CauseOfInterruption.UserInterruption" when user is missing

It is a regression introduced in JENKINS-36594

* [JENKINS-38721] - Fix typo

(cherry picked from commit 91ad592)
  • Loading branch information...
oleg-nenashev authored and olivergondza committed Nov 13, 2016
1 parent df1f2b2 commit 0399037f842d1c9c4fbbc970421fafa3ecdac7eb
@@ -33,6 +33,7 @@
import java.io.Serializable;
import java.util.Collections;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

/**
* Records why an {@linkplain Executor#interrupt() executor is interrupted}.
@@ -74,18 +75,46 @@ public void print(TaskListener listener) {
* Indicates that the build was interrupted from UI.
*/
public static final class UserInterruption extends CauseOfInterruption {

@Nonnull
private final String user;

public UserInterruption(User user) {
public UserInterruption(@Nonnull User user) {
this.user = user.getId();
}

public UserInterruption(String userId) {
public UserInterruption(@Nonnull String userId) {
this.user = userId;
}

@CheckForNull
/**
* Gets ID of the user, who interrupted the build.
* @return User ID
* @since TODO
*/
@Nonnull
public String getUserId() {
return user;
}

/**
* Gets user, who caused the interruption.
* @return User instance if it can be located.
* Result of {@link User#getUnknown()} otherwise
*/
@Nonnull
public User getUser() {
final User userInstance = getUserOrNull();
return userInstance != null ? userInstance : User.getUnknown();
}

/**
* Gets user, who caused the interruption.
* @return User or {@code null} if it has not been found
* @since TODO
*/
@CheckForNull
public User getUserOrNull() {
return User.get(user, false, Collections.emptyMap());
}

@@ -1,4 +1,9 @@
package jenkins.model.CauseOfInterruption.UserInterruption;

// by default we just print the short description.
raw(_("blurb",my.user.fullName, rootURL+'/'+my.user.url))
def user = my.userOrNull
if (user != null) {
raw(_("blurb", user.fullName, rootURL+'/'+user.url))
} else {
raw(_("userNotFound", my.userId))
}
@@ -1 +1,2 @@
blurb=Aborted by user <a href="{1}">{0}</a>
blurb=Aborted by user <a href="{1}">{0}</a>
userNotFound=Aborted by user {0}
@@ -1 +1,2 @@
blurb=\u30e6\u30fc\u30b6\u30fc <a href="{1}">{0}</a> \u306b\u3088\u308a\u4e2d\u65ad
blurb=\u30e6\u30fc\u30b6\u30fc <a href="{1}">{0}</a> \u306b\u3088\u308a\u4e2d\u65ad
userNotFound=\u30e6\u30fc\u30b6\u30fc {0} \u306b\u3088\u308a\u4e2d\u65ad
@@ -1 +1,2 @@
blurb=Przerwane przez u\u017Cytkownika <a href="{1}">{0}</a>
blurb=Przerwane przez u\u017cytkownika <a href="{1}">{0}</a>
userNotFound=Przerwane przez u\u017cytkownika {0}
@@ -0,0 +1,4 @@
# This file is under the MIT License by authors

blurb=\u041e\u0442\u043a\u0430\u0437\u0430\u043d\u043e \u043a\u043e\u0440\u0438\u0441\u043d\u0438\u043a\u043e\u043c <a href="{1}">{0}</a>
userNotFound=\u041e\u0442\u043a\u0430\u0437\u0430\u043d\u043e \u043a\u043e\u0440\u0438\u0441\u043d\u0438\u043a\u043e\u043c {0}
@@ -22,3 +22,4 @@
# THE SOFTWARE.

blurb=\u7531\u4f7f\u7528\u8005 <a href="{1}">{0}</a> \u4e2d\u6b62
userNotFound=\u7531\u4f7f\u7528\u8005 {0} \u4e2d\u6b62

0 comments on commit 0399037

Please sign in to comment.
You can’t perform that action at this time.