SubmitRuleEvaluator: Check state in getSubmitRule()
Change-Id: I849fe43db2619a2c503c24705f2479947b8ad058
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
package com.google.gerrit.server.project;
|
package com.google.gerrit.server.project;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -125,19 +126,19 @@ public class SubmitRuleEvaluator {
|
|||||||
String filterRuleWrapperName) throws RuleEvalException {
|
String filterRuleWrapperName) throws RuleEvalException {
|
||||||
PrologEnvironment env = getPrologEnvironment();
|
PrologEnvironment env = getPrologEnvironment();
|
||||||
try {
|
try {
|
||||||
submitRule = env.once("gerrit", userRuleLocatorName, new VariableTerm());
|
Term sr = env.once("gerrit", userRuleLocatorName, new VariableTerm());
|
||||||
if (fastEvalLabels) {
|
if (fastEvalLabels) {
|
||||||
env.once("gerrit", "assume_range_from_label");
|
env.once("gerrit", "assume_range_from_label");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Term> results = new ArrayList<>();
|
List<Term> results = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
for (Term[] template : env.all("gerrit", userRuleWrapperName,
|
for (Term[] template : env.all("gerrit", userRuleWrapperName, sr,
|
||||||
submitRule, new VariableTerm())) {
|
new VariableTerm())) {
|
||||||
results.add(template[1]);
|
results.add(template[1]);
|
||||||
}
|
}
|
||||||
} catch (RuntimeException err) {
|
} catch (RuntimeException err) {
|
||||||
throw new RuleEvalException("Exception calling " + submitRule
|
throw new RuleEvalException("Exception calling " + sr
|
||||||
+ " on change " + cd.getId() + " of " + getProjectName(),
|
+ " on change " + cd.getId() + " of " + getProjectName(),
|
||||||
err);
|
err);
|
||||||
}
|
}
|
||||||
@@ -147,16 +148,19 @@ public class SubmitRuleEvaluator {
|
|||||||
resultsTerm = runSubmitFilters(
|
resultsTerm = runSubmitFilters(
|
||||||
resultsTerm, env, filterRuleLocatorName, filterRuleWrapperName);
|
resultsTerm, env, filterRuleLocatorName, filterRuleWrapperName);
|
||||||
}
|
}
|
||||||
|
List<Term> r;
|
||||||
if (resultsTerm.isList()) {
|
if (resultsTerm.isList()) {
|
||||||
List<Term> r = Lists.newArrayList();
|
r = Lists.newArrayList();
|
||||||
for (Term t = resultsTerm; t.isList();) {
|
for (Term t = resultsTerm; t.isList();) {
|
||||||
ListTerm l = (ListTerm) t;
|
ListTerm l = (ListTerm) t;
|
||||||
r.add(l.car().dereference());
|
r.add(l.car().dereference());
|
||||||
t = l.cdr().dereference();
|
t = l.cdr().dereference();
|
||||||
}
|
}
|
||||||
return r;
|
} else {
|
||||||
|
r = Collections.emptyList();
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
submitRule = sr;
|
||||||
|
return r;
|
||||||
} finally {
|
} finally {
|
||||||
env.close();
|
env.close();
|
||||||
}
|
}
|
||||||
@@ -241,6 +245,7 @@ public class SubmitRuleEvaluator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Term getSubmitRule() {
|
public Term getSubmitRule() {
|
||||||
|
checkState(submitRule != null, "getSubmitRule() invalid before evaluation");
|
||||||
return submitRule;
|
return submitRule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user