RuntimeException injectElement()

in src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java [518:538]


    RuntimeException injectElement(final InjectableElement element, final Object adaptable,
                                   final @NotNull DisposalCallbackRegistry registry, final InjectCallback callback,
                                   final @NotNull Map<ValuePreparer, Object> preparedValues,
                                   final @Nullable BundleContext modelContext) {
        if (element instanceof InjectableField) {
            Type genericType = ((InjectableField) element).getFieldGenericType();

            if (genericType instanceof ParameterizedType) {
                ParameterizedType pType = (ParameterizedType) genericType;

                if (pType.getRawType().equals(Optional.class)) {
                    InjectableElement el = new OptionalTypedInjectableElement(element, pType.getActualTypeArguments()[0]);
                    InjectCallback wrappedCallback = new OptionalWrappingCallback(callback, element);

                    return injectElementInternal(el, adaptable, registry, wrappedCallback, preparedValues, modelContext);
                }
            }
        }

        return injectElementInternal(element, adaptable, registry, callback, preparedValues, modelContext);
    }