in src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java [832:859]
private <ModelType> Result<ModelType> newInstanceWithConstructorInjection(final ModelClassConstructor<ModelType> constructor, final Object adaptable,
final ModelClass<ModelType> modelClass, final DisposalCallbackRegistry registry, final @NotNull Map<ValuePreparer, Object> preparedValues)
throws InstantiationException, InvocationTargetException, IllegalAccessException {
ConstructorParameter[] parameters = constructor.getConstructorParameters();
List<Object> paramValues = new ArrayList<>(Arrays.asList(new Object[parameters.length]));
InjectCallback callback = new SetConstructorParameterCallback(paramValues);
final BundleContext modelContext = getModelBundleContext(modelClass);
List<MissingElementException> missingElements = null;
for (int i = 0; i < parameters.length; i++) {
RuntimeException t = injectElement(parameters[i], adaptable, registry, callback, preparedValues, modelContext);
if (t != null) {
if (missingElements == null) {
missingElements = new ArrayList<>();
}
missingElements.add(new MissingElementException(parameters[i].getAnnotatedElement(), t));
}
}
if (missingElements != null) {
MissingElementsException missingElementsException = new MissingElementsException("Required constructor parameters were not able to be injected on model " + modelClass.getType());
for (MissingElementException me : missingElements) {
missingElementsException.addMissingElementExceptions(me);
}
return new Result<>(missingElementsException);
}
return new Result<>(constructor.newInstance(paramValues.toArray(new Object[paramValues.size()])));
}