if (reference != null) {
final Object cache = values.get(getReferenceKey(reference));
</BUG>
if (cache == null) {
final ConversionException ex = new ConversionException("Invalid reference");
<BUG>ex.add("reference", reference);
throw ex;</BUG>
}
<BUG>result = cache == NULL ? null : cache;
} else {</BUG>
final R currentReferenceKey = getCurrentReferenceKey();

if (reference != null) {
final Object cache = isReferenceable ? values.get(getReferenceKey(reference)) : null;
if (cache == null) {
final ConversionException ex = new ConversionException("Invalid reference");
ex.add("reference", reference);
ex.add("referenced-type", type.getName());
ex.add("referenceable", Boolean.toString(isReferenceable));
throw ex;
}
result = cache == NULL ? null : cache;
} else if (!isReferenceable) {
result = super.convert(parent, type, converter);
} else {
final R currentReferenceKey = getCurrentReferenceKey();
