提交 0399037f 编写于 作者: O Oleg Nenashev 提交者: Oliver Gondža

[FIXED JENKINS-38721, JENKINS-37282] - NPE in...

[FIXED JENKINS-38721, JENKINS-37282] - NPE in "CauseOfInterruption.UserInterruption" 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 91ad5921)
上级 df1f2b2b
......@@ -33,6 +33,7 @@ import org.kohsuke.stapler.export.ExportedBean;
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 abstract class CauseOfInterruption implements Serializable {
* 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());
}
......
package jenkins.model.CauseOfInterruption.UserInterruption;
// by default we just print the short description.
raw(_("blurb",my.user.fullName, rootURL+'/'+my.user.url))
\ No newline at end of file
def user = my.userOrNull
if (user != null) {
raw(_("blurb", user.fullName, rootURL+'/'+user.url))
} else {
raw(_("userNotFound", my.userId))
}
blurb=Aborted by user <a href="{1}">{0}</a>
\ No newline at end of file
blurb=Aborted by user <a href="{1}">{0}</a>
userNotFound=Aborted by user {0}
blurb=\u30e6\u30fc\u30b6\u30fc <a href="{1}">{0}</a> \u306b\u3088\u308a\u4e2d\u65ad
\ No newline at end of file
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
blurb=Przerwane przez u\u017Cytkownika <a href="{1}">{0}</a>
\ No newline at end of file
blurb=Przerwane przez u\u017cytkownika <a href="{1}">{0}</a>
userNotFound=Przerwane przez u\u017cytkownika {0}
# 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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册