From 0857b455f61a38cd8ec96de9eef6c82c04f8a9a1 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Thu, 5 Mar 2015 00:09:15 +0100 Subject: Prevent invalid CommitStatus.state values see https://developer.github.com/v3/repos/statuses/ Change-Id: I62f8cbf1e276a3d3da270292153a80028c872b2c Signed-off-by: Matthias Sohn --- .../src/org/eclipse/egit/github/core/CommitStatus.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'org.eclipse.egit.github.core') diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/CommitStatus.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/CommitStatus.java index b6df83e4..e178014d 100644 --- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/CommitStatus.java +++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/CommitStatus.java @@ -11,6 +11,7 @@ package org.eclipse.egit.github.core; import java.io.Serializable; +import java.text.MessageFormat; import java.util.Date; import org.eclipse.egit.github.core.util.DateUtils; @@ -150,10 +151,15 @@ public class CommitStatus implements Serializable { /** * @param state * @return this status + * throws {@link IllegalArgumentException} if state is invalid */ public CommitStatus setState(final String state) { - this.state = state; - return this; + if (STATE_ERROR.equals(state) || STATE_FAILURE.equals(state) || STATE_PENDING.equals(state) + || STATE_SUCCESS.equals(state)) { + this.state = state; + return this; + } + throw new IllegalArgumentException(MessageFormat.format("Invalid state {0}", state)); } /** -- cgit v1.2.3