etugarev commented on a change in pull request #17:
URL: 
https://github.com/apache/sling-org-apache-sling-models-impl/pull/17#discussion_r444160872



##########
File path: src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
##########
@@ -495,12 +480,97 @@ public RuntimeException inject(InjectableElement element, 
Object value) {
         }
     }
 
+    @NotNull
+    private InjectableElement getElement(InjectableElement element, Type type) 
{
+        return new InjectableElement() {
+            @Override
+            public AnnotatedElement getAnnotatedElement() {
+                return element.getAnnotatedElement();
+            }
+
+            @Override
+            public Type getType() {
+                return type;
+            }
+
+            @Override
+            public boolean isPrimitive() {
+                return element.isPrimitive();
+            }
+
+            @Override
+            public String getName() {
+                return element.getName();
+            }
+
+            @Override
+            public String getSource() {
+                return element.getSource();
+            }
+
+            @Override
+            public String getVia() {
+                return element.getVia();
+            }
+
+            @Override
+            public Class<? extends ViaProviderType> getViaProviderType() {
+                return element.getViaProviderType();
+            }
+
+            @Override
+            public boolean hasDefaultValue() {
+                return element.hasDefaultValue();
+            }
+
+            @Override
+            public Object getDefaultValue() {
+                return element.getDefaultValue() == null ? Optional.empty() : 
element.getDefaultValue();

Review comment:
       Here, unfortunately, I have to provide a value which is not null, to 
make the injection successful. Since we don't have a specific injector for 
Optional type to handle a null value, eventually a default value injector will 
be executed last and injection will fail if the value is not present (null) 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to