target = targetReference.get().getInstance();
if (target == null) {
throw MESSAGES.injectionTargetNotFound();
}
}
final ManagedReference reference = factory.getReference();
if (reference == null && optional) {
return context.proceed();
} else if(reference == null) {
throw EeMessages.MESSAGES.managedReferenceWasNull(field);
}
boolean ok = false;
try {
valueReference.set(reference);
field.set(target, reference.getInstance());
Object result = context.proceed();
ok = true;
return result;
} finally {
if (!ok) {
valueReference.set(null);
reference.release();
}
}
}