提交 28dfd90d 编写于 作者: J Jesse Glick

Better to use an IllegalStateException rather than assertion in setResult.

Assertions are only for cases where you believe the failure of the condition is impossible.
For cases where external code might mistakenly make an incorrect call, throw an exception.
上级 7e09c4f8
......@@ -440,9 +440,18 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
return result;
}
/**
* Sets the {@link #getResult} of this build.
* Has no effect when the result is already set and worse than the proposed result.
* May only be called after the build has started and before it has moved into post-production
* (normally meaning both {@link #isInProgress} and {@link #isBuilding} are true).
* @param r the proposed new result
* @throws IllegalStateException if the build has not yet started, is in post-production, or is complete
*/
public void setResult(@Nonnull Result r) {
// state can change only when we are building
assert state==State.BUILDING : state;
if (state != State.BUILDING) {
throw new IllegalStateException("cannot change build result while in " + state);
}
// result can only get worse
if (result==null || r.isWorseThan(result)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册