Skip to content

Commit

Permalink
validate Category identifier to prevent assertation error
Browse files Browse the repository at this point in the history
  • Loading branch information
innerjoin committed Jun 2, 2017
1 parent cfeedab commit 6a68ff7
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.repository.service.IRepositoryItemService;
import com.ibm.team.repository.service.TeamRawService;
import com.ibm.team.workitem.common.internal.util.CategoriesHelper;
import com.ibm.team.workitem.common.model.CategoryId;
import com.ibm.team.workitem.common.model.ICategory;
import com.ibm.team.workitem.common.model.ICategoryHandle;
Expand Down Expand Up @@ -32,9 +33,11 @@ public static final AttributeValue getCategory(Object t_val,
public static final void setCategory(IWorkItem workItem, String categoryId,
IWorkItemServer workItemServer, IProgressMonitor monitor) throws TeamRepositoryException {
IProjectAreaHandle ipa = workItem.getProjectArea();
CategoryId cid = CategoryId.createCategoryId(categoryId);
ICategoryHandle cat = workItemServer.findCategoryById2(ipa, cid, monitor);
workItem.setCategory(cat);
if(isValidCategoryId(categoryId)) {
CategoryId cid = CategoryId.createCategoryId(categoryId);
ICategoryHandle cat = workItemServer.findCategoryById2(ipa, cid, monitor);
workItem.setCategory(cat);
}
}

public static final List<AttributeValue> addCategoriesAsValues(IProjectAreaHandle pa,
Expand All @@ -51,4 +54,8 @@ public static final List<AttributeValue> addCategoriesAsValues(IProjectAreaHandl
}
return values;
}

public static boolean isValidCategoryId(String string) {
return string.startsWith("/") && string.indexOf("/", "/".length()) != -1;
}
}

0 comments on commit 6a68ff7

Please sign in to comment.