Program: 8831
Project: 8831
Buggy source:
/** 
 * Converts the given value to a value of the specified target type. The conversion is performed according to the rules described in "3.6.4 Property Type Conversion" in the JCR 2.0 specification.
 * @param value the value to convert
 * @param targetType the target property type 
 * @param mapper the name mapper
 * @return the converted value
 * @throws IllegalArgumentException if mapping is illegal
 */
public static PropertyValue convert(PropertyValue value,int targetType,NamePathMapper mapper){
  int sourceType=value.getType().tag();
  if (sourceType == targetType) {
    return value;
  }
switch (targetType) {
case PropertyType.BINARY:
    Blob blob=value.getValue(Type.BINARY);
  return newBinary(blob);
case PropertyType.BOOLEAN:
return newBoolean(value.getValue(Type.BOOLEAN));
case PropertyType.DATE:
return newDate(value.getValue(Type.DATE));
case PropertyType.DOUBLE:
return newDouble(value.getValue(Type.DOUBLE));
case PropertyType.LONG:
return newLong(value.getValue(Type.LONG));
case PropertyType.DECIMAL:
return newDecimal(value.getValue(Type.DECIMAL));
}
String v=value.getValue(Type.STRING);
switch (targetType) {
case PropertyType.STRING:
return newString(v);
case PropertyType.PATH:
switch (sourceType) {
case PropertyType.BINARY:
case PropertyType.STRING:
case PropertyType.NAME:
return newPath(v);
case PropertyType.URI:
URI uri=URI.create(v);
if (uri.isAbsolute()) {
throw new IllegalArgumentException("String_Node_Str" + v + "String_Node_Str");
}
String p=uri.getPath();
if (p.startsWith("String_Node_Str")) {
p=p.substring(2);
}
return newPath(v);
}
break;
case PropertyType.NAME:
switch (sourceType) {
case PropertyType.BINARY:
case PropertyType.STRING:
case PropertyType.PATH:
return newName(getOakPath(v,mapper));
case PropertyType.URI:
URI uri=URI.create(v);
if (uri.isAbsolute()) {
throw new IllegalArgumentException("String_Node_Str" + v + "String_Node_Str");
}
String p=uri.getPath();
if (p.startsWith("String_Node_Str")) {
p=p.substring(2);
}
return newName(getOakPath(v,mapper));
}
break;
case PropertyType.REFERENCE:
switch (sourceType) {
case PropertyType.BINARY:
case PropertyType.STRING:
case PropertyType.WEAKREFERENCE:
return newReference(v);
}
break;
case PropertyType.WEAKREFERENCE:
switch (sourceType) {
case PropertyType.BINARY:
case PropertyType.STRING:
case PropertyType.REFERENCE:
return newWeakReference(v);
}
break;
case PropertyType.URI:
switch (sourceType) {
case PropertyType.BINARY:
case PropertyType.STRING:
return newUri(v);
case PropertyType.NAME:
return newUri("String_Node_Str" + v);
case PropertyType.PATH:
return newUri("String_Node_Str" + v);
}
}
throw new IllegalArgumentException("String_Node_Str" + PropertyType.nameFromValue(sourceType) + "String_Node_Str"+ PropertyType.nameFromValue(targetType));
}

Fixed version (ground truth):
/** 
 * Converts the given value to a value of the specified target type. The conversion is performed according to the rules described in "3.6.4 Property Type Conversion" in the JCR 2.0 specification.
 * @param value the value to convert
 * @param targetType the target property type 
 * @param mapper the name mapper
 * @return the converted value
 * @throws IllegalArgumentException if mapping is illegal
 */
public static PropertyValue convert(@Nonnull PropertyValue value,int targetType,@Nonnull NamePathMapper mapper){
  int sourceType=value.getType().tag();
  if (sourceType == targetType) {
    return value;
  }
switch (targetType) {
case PropertyType.BINARY:
    Blob blob=value.getValue(Type.BINARY);
  return newBinary(blob);
case PropertyType.BOOLEAN:
return newBoolean(value.getValue(Type.BOOLEAN));
case PropertyType.DATE:
return newDate(value.getValue(Type.DATE));
case PropertyType.DOUBLE:
return newDouble(value.getValue(Type.DOUBLE));
case PropertyType.LONG:
return newLong(value.getValue(Type.LONG));
case PropertyType.DECIMAL:
return newDecimal(value.getValue(Type.DECIMAL));
}
String v=value.getValue(Type.STRING);
switch (targetType) {
case PropertyType.STRING:
return newString(v);
case PropertyType.PATH:
switch (sourceType) {
case PropertyType.BINARY:
case PropertyType.STRING:
case PropertyType.NAME:
return newPath(v);
case PropertyType.URI:
URI uri=URI.create(v);
if (uri.isAbsolute()) {
throw new IllegalArgumentException("String_Node_Str" + v + "String_Node_Str");
}
String p=uri.getPath();
if (p.startsWith("String_Node_Str")) {
p=p.substring(2);
}
return newPath(v);
}
break;
case PropertyType.NAME:
switch (sourceType) {
case PropertyType.BINARY:
case PropertyType.STRING:
case PropertyType.PATH:
return newName(getOakPath(v,mapper));
case PropertyType.URI:
URI uri=URI.create(v);
if (uri.isAbsolute()) {
throw new IllegalArgumentException("String_Node_Str" + v + "String_Node_Str");
}
String p=uri.getPath();
if (p.startsWith("String_Node_Str")) {
p=p.substring(2);
}
return newName(getOakPath(v,mapper));
}
break;
case PropertyType.REFERENCE:
switch (sourceType) {
case PropertyType.BINARY:
case PropertyType.STRING:
case PropertyType.WEAKREFERENCE:
return newReference(v);
}
break;
case PropertyType.WEAKREFERENCE:
switch (sourceType) {
case PropertyType.BINARY:
case PropertyType.STRING:
case PropertyType.REFERENCE:
return newWeakReference(v);
}
break;
case PropertyType.URI:
switch (sourceType) {
case PropertyType.BINARY:
case PropertyType.STRING:
return newUri(v);
case PropertyType.NAME:
return newUri("String_Node_Str" + v);
case PropertyType.PATH:
return newUri("String_Node_Str" + v);
}
}
throw new IllegalArgumentException("String_Node_Str" + PropertyType.nameFromValue(sourceType) + "String_Node_Str"+ PropertyType.nameFromValue(targetType));
}