Handle null/undefined JsArrays as empty in Natives.asList()

Fix a resulting bug in PublishCommentScreen causing an error when
nobody has voted on a particular label.

Change-Id: I0c6bfbfa4ea151df4e9b588251fd1895745a7edb
This commit is contained in:
Dave Borowitz
2013-02-08 17:06:04 -08:00
parent ed8535a7a5
commit b32df3609e
2 changed files with 9 additions and 4 deletions

View File

@@ -267,10 +267,12 @@ public class PublishCommentScreen extends AccountScreen implements
vp.setStyleName(Gerrit.RESOURCES.css().approvalCategoryList()); vp.setStyleName(Gerrit.RESOURCES.css().approvalCategoryList());
Short prior = null; Short prior = null;
for (ApprovalInfo app : Natives.asList(label.all())) { if (label.all() != null) {
if (app._account_id() == Gerrit.getUserAccount().getId().get()) { for (ApprovalInfo app : Natives.asList(label.all())) {
prior = app.value(); if (app._account_id() == Gerrit.getUserAccount().getId().get()) {
break; prior = app.value();
break;
}
} }
} }

View File

@@ -37,6 +37,9 @@ public class Natives {
public static <T extends JavaScriptObject> List<T> asList( public static <T extends JavaScriptObject> List<T> asList(
final JsArray<T> arr) { final JsArray<T> arr) {
if (arr == null) {
return null;
}
return new AbstractList<T>() { return new AbstractList<T>() {
@Override @Override
public T set(int index, T element) { public T set(int index, T element) {