PropertyConstraintException for 'scm create changeset'
When trying to create a changeset using the command line interface (scm) I got
The comment for the changeset is auto-generated and long (1033 lines, 44538 characters). Could that be the reason for the exception? I have seen this exception several times and always long comments were involved. For short comments I have not seen the exception yet. Is there a limit to the length of change set comments? I could not find a documented limit so far, but I might have looked in the wrong places.
Thanks,
Daniel
com.ibm.team.repository.common.validation.PropertyConstraintException: Validation errors for item: type = ChangeSet, itemId = [UUID ...]
at com.ibm.team.scm.common.internal.util.ValidationUtils.checkPropertyConstraints(ValidationUtils.java:33)
at com.ibm.team.scm.service.internal.operations.CreateChangeSetOperation.run(CreateChangeSetOperation.java:70)
at com.ibm.team.scm.service.internal.ScmService$16.run(ScmService.java:794)
at com.ibm.team.scm.service.internal.AbstractScmService$3.run(AbstractScmService.java:574)
...
The comment for the changeset is auto-generated and long (1033 lines, 44538 characters). Could that be the reason for the exception? I have seen this exception several times and always long comments were involved. For short comments I have not seen the exception yet. Is there a limit to the length of change set comments? I could not find a documented limit so far, but I might have looked in the wrong places.
Thanks,
Daniel
3 answers
Well, I suppose that Java code won't really help for the command line, but at least I can confirm that would be why you can't save a change set.
But here's a non-internal way on how to truncate it yourself the Java way:
But here's a non-internal way on how to truncate it yourself the Java way:
...
String shorterComment = truncate(IChangeSet.ITEM_TYPE, IChangeSet.COMMENT_PROPERTY, longComment);
public static String truncate(IType type, String propertyName, String value) {
if (value == null)
return value;
IStatus status= IItemValidator.INSTANCE.validateAttribute(type, propertyName, value);
if (status instanceof IStringSizeConstraintErrorStatus) {
long maxSize= ((IStringSizeConstraintErrorStatus) status).getMaxSize();
//max size is in number of bytes and substring is in number of characters.
//First do a rough truncation so truncate to maxBytes. i.e. #chars >= #bytes >= maxSize.
String truncated= value.substring(0, (int) Math.min(value.length(), maxSize));
//Here, #chars may be <maxSize> maxSize.
//incrementally cut down the length of the string until #bytes <maxSize> 0 && status instanceof IStringSizeConstraintErrorStatus);
return truncated;
}
return value;
}
private static String endAtWordBoundary(String string) {
int space= string.lastIndexOf(' ');
if (space > 0)
return string.substring(0, space);
if (string.length() > 1)
return string.substring(0, string.length() - 1);
return "";
}
...The comment for the changeset is auto-generated and long (1033 lines, 44538 characters).
...
Thanks,
Daniel
Yes, that is the issue. I don't recall offhand what the max byte size is for the change set comment property, but you can use this helper method to provide you with the longest possible comment that is valid (it will only truncate if it needs to)
String shorterComment = com.ibm.team.scm.common.internal.util.ValidationUtils.truncate(IChangeSet.ITEM_TYPE, IChangeSet.COMMENT_PROPERTY, longComment);