Program: 8750
Project: 8750
Buggy source:
/** 
 * <i>Copied from Apache Jackrabbit Core</i> <p> Calculates the name of the new version that will be created by a checkin call. The name is determined as follows: <ul> <li> first the predecessor version with the shortest name is searched. <li> if that predecessor version is the root version, the new version gets the name "{number of successors}+1" + ".0" <li> if that predecessor version has no successor, the last digit of it's version number is incremented. <li> if that predecessor version has successors but the incremented name does not exist, that name is used. <li> otherwise a ".0" is added to the name until a non conflicting name is found. <ul> </p> Example Graph: <pre> jcr:rootVersion |     | 1.0   2.0 | 1.1 | 1.2 ---\  ------\ |      \        \ 1.3   1.2.0   1.2.0.0 |      | 1.4   1.2.1 ----\ |      |        \ 1.5   1.2.2   1.2.1.0 |      |        | 1.6     |     1.2.1.1 |-----/ 1.7 </pre>
 * @param history the version history
 * @param versionable the node to checkin
 * @return the new version name
 * @throws IllegalStateException if mandatory version properties are missing.
 */
protected String calculateVersion(@Nonnull NodeBuilder history,@Nonnull NodeBuilder versionable) throws IllegalStateException {
  PropertyState predecessors=versionable.getProperty(JCR_PREDECESSORS);
  if (predecessors == null || predecessors.count() == 0) {
    String message;
    if (predecessors == null) {
      message="String_Node_Str" + uuidFromNode(versionable);
    }
 else {
      message="String_Node_Str" + uuidFromNode(versionable);
    }
    throw new IllegalStateException(message);
  }
  String best=null;
  for (  String id : predecessors.getValue(Type.REFERENCES)) {
    String name=PathUtils.getName(getIdentifierManager().getPath(id));
    if (best == null || name.length() < best.length()) {
      best=name;
    }
  }
  if (best == null) {
    String message="String_Node_Str" + uuidFromNode(versionable);
    throw new IllegalStateException(message);
  }
  String versionName=best;
  int pos=versionName.lastIndexOf('.');
  if (pos > 0) {
    String newVersionName=versionName.substring(0,pos + 1) + (Integer.parseInt(versionName.substring(pos + 1)) + 1);
    while (history.hasChildNode(newVersionName)) {
      versionName+="String_Node_Str";
      newVersionName=versionName;
    }
    return newVersionName;
  }
 else {
    checkState(history.hasChildNode(JCR_ROOTVERSION));
    NodeBuilder v=history.getChildNode(JCR_ROOTVERSION);
    return String.valueOf(v.getProperty(JCR_SUCCESSORS).count() + 1) + "String_Node_Str";
  }
}

Fixed version (ground truth):
/** 
 * <i>Copied from Apache Jackrabbit Core</i> <p> Calculates the name of the new version that will be created by a checkin call. The name is determined as follows: <ul> <li> first the predecessor version with the shortest name is searched. <li> if that predecessor version is the root version, the new version gets the name "{number of successors}+1" + ".0" <li> if that predecessor version has no successor, the last digit of it's version number is incremented. <li> if that predecessor version has successors but the incremented name does not exist, that name is used. <li> otherwise a ".0" is added to the name until a non conflicting name is found. </ul> <p> Example Graph: <pre> jcr:rootVersion |     | 1.0   2.0 | 1.1 | 1.2 ---\  ------\ |      \        \ 1.3   1.2.0   1.2.0.0 |      | 1.4   1.2.1 ----\ |      |        \ 1.5   1.2.2   1.2.1.0 |      |        | 1.6     |     1.2.1.1 |-----/ 1.7 </pre>
 * @param history the version history
 * @param versionable the node to checkin
 * @return the new version name
 * @throws IllegalStateException if mandatory version properties are missing.
 */
protected String calculateVersion(@Nonnull NodeBuilder history,@Nonnull NodeBuilder versionable) throws IllegalStateException {
  PropertyState predecessors=versionable.getProperty(JCR_PREDECESSORS);
  if (predecessors == null || predecessors.count() == 0) {
    String message;
    if (predecessors == null) {
      message="String_Node_Str" + uuidFromNode(versionable);
    }
 else {
      message="String_Node_Str" + uuidFromNode(versionable);
    }
    throw new IllegalStateException(message);
  }
  String best=null;
  for (  String id : predecessors.getValue(Type.REFERENCES)) {
    String name=PathUtils.getName(getIdentifierManager().getPath(id));
    if (best == null || name.length() < best.length()) {
      best=name;
    }
  }
  if (best == null) {
    String message="String_Node_Str" + uuidFromNode(versionable);
    throw new IllegalStateException(message);
  }
  String versionName=best;
  int pos=versionName.lastIndexOf('.');
  if (pos > 0) {
    String newVersionName=versionName.substring(0,pos + 1) + (Integer.parseInt(versionName.substring(pos + 1)) + 1);
    while (history.hasChildNode(newVersionName)) {
      versionName+="String_Node_Str";
      newVersionName=versionName;
    }
    return newVersionName;
  }
 else {
    checkState(history.hasChildNode(JCR_ROOTVERSION));
    NodeBuilder v=history.getChildNode(JCR_ROOTVERSION);
    return String.valueOf(v.getProperty(JCR_SUCCESSORS).count() + 1) + "String_Node_Str";
  }
}