Merge "Fix NullPointerException in ChangeData.getLabelTypes()"
This commit is contained in:
@@ -758,8 +758,8 @@ public class ChangeData {
|
|||||||
return change;
|
return change;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LabelTypes getLabelTypes() {
|
public LabelTypes getLabelTypes() throws OrmException {
|
||||||
return changeControl.getLabelTypes();
|
return changeControl().getLabelTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChangeNotes notes() throws OrmException {
|
public ChangeNotes notes() throws OrmException {
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ import com.google.gerrit.server.CurrentUser;
|
|||||||
import com.google.gerrit.server.permissions.LabelPermission;
|
import com.google.gerrit.server.permissions.LabelPermission;
|
||||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||||
import com.google.gerrit.server.query.change.ChangeData;
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.googlecode.prolog_cafe.exceptions.IllegalTypeException;
|
import com.googlecode.prolog_cafe.exceptions.IllegalTypeException;
|
||||||
|
import com.googlecode.prolog_cafe.exceptions.JavaException;
|
||||||
import com.googlecode.prolog_cafe.exceptions.PInstantiationException;
|
import com.googlecode.prolog_cafe.exceptions.PInstantiationException;
|
||||||
import com.googlecode.prolog_cafe.exceptions.PrologException;
|
import com.googlecode.prolog_cafe.exceptions.PrologException;
|
||||||
import com.googlecode.prolog_cafe.exceptions.SystemException;
|
import com.googlecode.prolog_cafe.exceptions.SystemException;
|
||||||
@@ -80,19 +82,20 @@ class PRED__check_user_label_3 extends Predicate.P3 {
|
|||||||
}
|
}
|
||||||
short val = (short) ((IntegerTerm) a3).intValue();
|
short val = (short) ((IntegerTerm) a3).intValue();
|
||||||
|
|
||||||
ChangeData cd = StoredValues.CHANGE_DATA.get(engine);
|
|
||||||
LabelType type = cd.getLabelTypes().byLabel(label);
|
|
||||||
if (type == null) {
|
|
||||||
return engine.fail();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
ChangeData cd = StoredValues.CHANGE_DATA.get(engine);
|
||||||
|
LabelType type = cd.getLabelTypes().byLabel(label);
|
||||||
|
if (type == null) {
|
||||||
|
return engine.fail();
|
||||||
|
}
|
||||||
StoredValues.PERMISSION_BACKEND
|
StoredValues.PERMISSION_BACKEND
|
||||||
.get(engine)
|
.get(engine)
|
||||||
.user(user)
|
.user(user)
|
||||||
.change(cd)
|
.change(cd)
|
||||||
.check(new LabelPermission.WithValue(type, val));
|
.check(new LabelPermission.WithValue(type, val));
|
||||||
return cont;
|
return cont;
|
||||||
|
} catch (OrmException err) {
|
||||||
|
throw new JavaException(this, 1, err);
|
||||||
} catch (AuthException err) {
|
} catch (AuthException err) {
|
||||||
return engine.fail();
|
return engine.fail();
|
||||||
} catch (PermissionBackendException err) {
|
} catch (PermissionBackendException err) {
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ import com.google.gerrit.server.CurrentUser;
|
|||||||
import com.google.gerrit.server.permissions.LabelPermission;
|
import com.google.gerrit.server.permissions.LabelPermission;
|
||||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||||
import com.google.gerrit.server.query.change.ChangeData;
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.googlecode.prolog_cafe.exceptions.IllegalTypeException;
|
import com.googlecode.prolog_cafe.exceptions.IllegalTypeException;
|
||||||
|
import com.googlecode.prolog_cafe.exceptions.JavaException;
|
||||||
import com.googlecode.prolog_cafe.exceptions.PInstantiationException;
|
import com.googlecode.prolog_cafe.exceptions.PInstantiationException;
|
||||||
import com.googlecode.prolog_cafe.exceptions.PrologException;
|
import com.googlecode.prolog_cafe.exceptions.PrologException;
|
||||||
import com.googlecode.prolog_cafe.exceptions.SystemException;
|
import com.googlecode.prolog_cafe.exceptions.SystemException;
|
||||||
@@ -74,15 +76,16 @@ class PRED__user_label_range_4 extends Predicate.P4 {
|
|||||||
}
|
}
|
||||||
CurrentUser user = (CurrentUser) ((JavaObjectTerm) a2).object();
|
CurrentUser user = (CurrentUser) ((JavaObjectTerm) a2).object();
|
||||||
|
|
||||||
ChangeData cd = StoredValues.CHANGE_DATA.get(engine);
|
|
||||||
LabelType type = cd.getLabelTypes().byLabel(label);
|
|
||||||
if (type == null) {
|
|
||||||
return engine.fail();
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<LabelPermission.WithValue> can;
|
Set<LabelPermission.WithValue> can;
|
||||||
try {
|
try {
|
||||||
|
ChangeData cd = StoredValues.CHANGE_DATA.get(engine);
|
||||||
|
LabelType type = cd.getLabelTypes().byLabel(label);
|
||||||
|
if (type == null) {
|
||||||
|
return engine.fail();
|
||||||
|
}
|
||||||
can = StoredValues.PERMISSION_BACKEND.get(engine).user(user).change(cd).test(type);
|
can = StoredValues.PERMISSION_BACKEND.get(engine).user(user).change(cd).test(type);
|
||||||
|
} catch (OrmException err) {
|
||||||
|
throw new JavaException(this, 1, err);
|
||||||
} catch (PermissionBackendException err) {
|
} catch (PermissionBackendException err) {
|
||||||
SystemException se = new SystemException(err.getMessage());
|
SystemException se = new SystemException(err.getMessage());
|
||||||
se.initCause(err);
|
se.initCause(err);
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ package gerrit;
|
|||||||
import com.google.gerrit.common.data.LabelType;
|
import com.google.gerrit.common.data.LabelType;
|
||||||
import com.google.gerrit.common.data.LabelValue;
|
import com.google.gerrit.common.data.LabelValue;
|
||||||
import com.google.gerrit.rules.StoredValues;
|
import com.google.gerrit.rules.StoredValues;
|
||||||
|
import com.google.gwtorm.server.OrmException;
|
||||||
|
import com.googlecode.prolog_cafe.exceptions.JavaException;
|
||||||
import com.googlecode.prolog_cafe.exceptions.PrologException;
|
import com.googlecode.prolog_cafe.exceptions.PrologException;
|
||||||
import com.googlecode.prolog_cafe.lang.IntegerTerm;
|
import com.googlecode.prolog_cafe.lang.IntegerTerm;
|
||||||
import com.googlecode.prolog_cafe.lang.ListTerm;
|
import com.googlecode.prolog_cafe.lang.ListTerm;
|
||||||
@@ -51,7 +53,12 @@ class PRED_get_legacy_label_types_1 extends Predicate.P1 {
|
|||||||
public Operation exec(Prolog engine) throws PrologException {
|
public Operation exec(Prolog engine) throws PrologException {
|
||||||
engine.setB0();
|
engine.setB0();
|
||||||
Term a1 = arg1.dereference();
|
Term a1 = arg1.dereference();
|
||||||
List<LabelType> list = StoredValues.CHANGE_DATA.get(engine).getLabelTypes().getLabelTypes();
|
List<LabelType> list;
|
||||||
|
try {
|
||||||
|
list = StoredValues.CHANGE_DATA.get(engine).getLabelTypes().getLabelTypes();
|
||||||
|
} catch (OrmException err) {
|
||||||
|
throw new JavaException(this, 1, err);
|
||||||
|
}
|
||||||
Term head = Prolog.Nil;
|
Term head = Prolog.Nil;
|
||||||
for (int idx = list.size() - 1; 0 <= idx; idx--) {
|
for (int idx = list.size() - 1; 0 <= idx; idx--) {
|
||||||
head = new ListTerm(export(list.get(idx)), head);
|
head = new ListTerm(export(list.get(idx)), head);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class GerritCommonTest extends PrologTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUpEnvironment(PrologEnvironment env) {
|
protected void setUpEnvironment(PrologEnvironment env) throws Exception {
|
||||||
LabelTypes labelTypes = new LabelTypes(Arrays.asList(Util.codeReview(), Util.verified()));
|
LabelTypes labelTypes = new LabelTypes(Arrays.asList(Util.codeReview(), Util.verified()));
|
||||||
ChangeData cd = EasyMock.createMock(ChangeData.class);
|
ChangeData cd = EasyMock.createMock(ChangeData.class);
|
||||||
expect(cd.getLabelTypes()).andStubReturn(labelTypes);
|
expect(cd.getLabelTypes()).andStubReturn(labelTypes);
|
||||||
@@ -63,12 +63,12 @@ public class GerritCommonTest extends PrologTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void gerritCommon() {
|
public void gerritCommon() throws Exception {
|
||||||
runPrologBasedTests();
|
runPrologBasedTests();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void reductionLimit() throws CompileException {
|
public void reductionLimit() throws Exception {
|
||||||
PrologEnvironment env = envFactory.create(machine);
|
PrologEnvironment env = envFactory.create(machine);
|
||||||
setUpEnvironment(env);
|
setUpEnvironment(env);
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public abstract class PrologTestCase extends GerritBaseTests {
|
|||||||
*
|
*
|
||||||
* @param env Prolog environment.
|
* @param env Prolog environment.
|
||||||
*/
|
*/
|
||||||
protected void setUpEnvironment(PrologEnvironment env) {}
|
protected void setUpEnvironment(PrologEnvironment env) throws Exception {}
|
||||||
|
|
||||||
private PrologMachineCopy newMachine() {
|
private PrologMachineCopy newMachine() {
|
||||||
BufferingPrologControl ctl = new BufferingPrologControl();
|
BufferingPrologControl ctl = new BufferingPrologControl();
|
||||||
@@ -115,7 +115,7 @@ public abstract class PrologTestCase extends GerritBaseTests {
|
|||||||
return env.execute(Prolog.BUILTIN, "clause", head, new VariableTerm());
|
return env.execute(Prolog.BUILTIN, "clause", head, new VariableTerm());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runPrologBasedTests() {
|
public void runPrologBasedTests() throws Exception {
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
long start = TimeUtil.nowMs();
|
long start = TimeUtil.nowMs();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user