target = ((ManagedReference) componentInstance.getInstanceData(targetKey)).getInstance();
if (target == null) {
throw EeLogger.ROOT_LOGGER.injectionTargetNotFound();
}
}
ManagedReference reference = factory.getReference();
if (reference == null && optional) {
return context.proceed();
}
boolean ok = false;
try {
componentInstance.setInstanceData(valueKey, reference);
final InvocationType invocationType = context.getPrivateData(InvocationType.class);
try {
context.putPrivateData(InvocationType.class, InvocationType.DEPENDENCY_INJECTION);
method.invoke(target, reference.getInstance());
} finally {
context.putPrivateData(InvocationType.class, invocationType);
}
Object result = context.proceed();
ok = true;
return result;
} finally {
if (!ok) {
componentInstance.setInstanceData(valueKey, null);
reference.release();
}
}
}