[jira] [Commented] (SLING-4447) Improve JavaUseProvider to not fall back to a simple Pojo instantiation in case a Java class with @Model annotation cannot be instantiated
[ https://issues.apache.org/jira/browse/SLING-4447?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=14526508#comment-14526508 ] Konrad Windszus commented on SLING-4447: [~rombert] Thanks a lot. Improve JavaUseProvider to not fall back to a simple Pojo instantiation in case a Java class with @Model annotation cannot be instantiated -- Key: SLING-4447 URL: https://issues.apache.org/jira/browse/SLING-4447 Project: Sling Issue Type: Improvement Components: Scripting Affects Versions: Scripting Sightly Engine 1.0.0 Reporter: Konrad Windszus Assignee: Konrad Windszus Fix For: Scripting Sightly Models Use Provider 1.0.0 Attachments: SLING-4447-v01.patch Currently in case a Java class is a Sling Model (i.e. has the Model annotation) and cannot be instantiated (e.g. required injections not possible) Sightly falls back to instantiate those as simple Pojos. This is never good, since a lot of NullPointerException might happen because all injections have not been performed then. Therefore in the following code should be used instead {code} if (modelFactory.isModelClass(resource, cls)) { if (modelFactory.canCreateFromAdaptable(resource, cls)) { obj = modelFactory.createModel(resource, cls); } else if (modelFactory.canCreateFromAdaptable(request, cls)) { obj = modelFactory.createModel(request, cls); } else { throw new IllegalStateException(Could not adapt the given Sling Model from neither resource nor request: + cls); } } {code} That way, exceptions would be propagated in case a Sling model cannot be instantiated and developers more easily see why the Sling Model does not work (instead of running into NullPointerExceptions in their model because it was instantiated as simple Pojo) -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (SLING-4447) Improve JavaUseProvider to not fall back to a simple Pojo instantiation in case a Java class with @Model annotation cannot be instantiated
[ https://issues.apache.org/jira/browse/SLING-4447?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=14526419#comment-14526419 ] Robert Munteanu commented on SLING-4447: [~kwin] - you should be able to add the new version yourself right now Improve JavaUseProvider to not fall back to a simple Pojo instantiation in case a Java class with @Model annotation cannot be instantiated -- Key: SLING-4447 URL: https://issues.apache.org/jira/browse/SLING-4447 Project: Sling Issue Type: Improvement Components: Scripting Affects Versions: Scripting Sightly Engine 1.0.0 Reporter: Konrad Windszus Assignee: Konrad Windszus Attachments: SLING-4447-v01.patch Currently in case a Java class is a Sling Model (i.e. has the Model annotation) and cannot be instantiated (e.g. required injections not possible) Sightly falls back to instantiate those as simple Pojos. This is never good, since a lot of NullPointerException might happen because all injections have not been performed then. Therefore in the following code should be used instead {code} if (modelFactory.isModelClass(resource, cls)) { if (modelFactory.canCreateFromAdaptable(resource, cls)) { obj = modelFactory.createModel(resource, cls); } else if (modelFactory.canCreateFromAdaptable(request, cls)) { obj = modelFactory.createModel(request, cls); } else { throw new IllegalStateException(Could not adapt the given Sling Model from neither resource nor request: + cls); } } {code} That way, exceptions would be propagated in case a Sling model cannot be instantiated and developers more easily see why the Sling Model does not work (instead of running into NullPointerExceptions in their model because it was instantiated as simple Pojo) -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (SLING-4447) Improve JavaUseProvider to not fall back to a simple Pojo instantiation in case a Java class with @Model annotation cannot be instantiated
[ https://issues.apache.org/jira/browse/SLING-4447?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=14521563#comment-14521563 ] Konrad Windszus commented on SLING-4447: In r1677000 I moved that class into a new bundle below contrib/scripting/sightly. Can someone with the according karma create a version 1.0.0 in JIRA for that module? Improve JavaUseProvider to not fall back to a simple Pojo instantiation in case a Java class with @Model annotation cannot be instantiated -- Key: SLING-4447 URL: https://issues.apache.org/jira/browse/SLING-4447 Project: Sling Issue Type: Improvement Components: Scripting Affects Versions: Scripting Sightly Engine 1.0.0 Reporter: Konrad Windszus Assignee: Konrad Windszus Fix For: Sling Models Impl 1.2.0 Attachments: SLING-4447-v01.patch Currently in case a Java class is a Sling Model (i.e. has the Model annotation) and cannot be instantiated (e.g. required injections not possible) Sightly falls back to instantiate those as simple Pojos. This is never good, since a lot of NullPointerException might happen because all injections have not been performed then. Therefore in the following code should be used instead {code} if (modelFactory.isModelClass(resource, cls)) { if (modelFactory.canCreateFromAdaptable(resource, cls)) { obj = modelFactory.createModel(resource, cls); } else if (modelFactory.canCreateFromAdaptable(request, cls)) { obj = modelFactory.createModel(request, cls); } else { throw new IllegalStateException(Could not adapt the given Sling Model from neither resource nor request: + cls); } } {code} That way, exceptions would be propagated in case a Sling model cannot be instantiated and developers more easily see why the Sling Model does not work (instead of running into NullPointerExceptions in their model because it was instantiated as simple Pojo) -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (SLING-4447) Improve JavaUseProvider to not fall back to a simple Pojo instantiation in case a Java class with @Model annotation cannot be instantiated
[ https://issues.apache.org/jira/browse/SLING-4447?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=14494133#comment-14494133 ] Radu Cotescu commented on SLING-4447: - I've fixed the unexported dependency issue in SLING-4618. Improve JavaUseProvider to not fall back to a simple Pojo instantiation in case a Java class with @Model annotation cannot be instantiated -- Key: SLING-4447 URL: https://issues.apache.org/jira/browse/SLING-4447 Project: Sling Issue Type: Improvement Components: Scripting Affects Versions: Scripting Sightly Engine 1.0.0 Reporter: Konrad Windszus Assignee: Konrad Windszus Fix For: Sling Models Impl 1.2.0 Attachments: SLING-4447-v01.patch Currently in case a Java class is a Sling Model (i.e. has the Model annotation) and cannot be instantiated (e.g. required injections not possible) Sightly falls back to instantiate those as simple Pojos. This is never good, since a lot of NullPointerException might happen because all injections have not been performed then. Therefore in the following code should be used instead {code} if (modelFactory.isModelClass(resource, cls)) { if (modelFactory.canCreateFromAdaptable(resource, cls)) { obj = modelFactory.createModel(resource, cls); } else if (modelFactory.canCreateFromAdaptable(request, cls)) { obj = modelFactory.createModel(request, cls); } else { throw new IllegalStateException(Could not adapt the given Sling Model from neither resource nor request: + cls); } } {code} That way, exceptions would be propagated in case a Sling model cannot be instantiated and developers more easily see why the Sling Model does not work (instead of running into NullPointerExceptions in their model because it was instantiated as simple Pojo) -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (SLING-4447) Improve JavaUseProvider to not fall back to a simple Pojo instantiation in case a Java class with @Model annotation cannot be instantiated
[ https://issues.apache.org/jira/browse/SLING-4447?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=14485149#comment-14485149 ] Radu Cotescu commented on SLING-4447: - I'm working in parallel to move Sightly out of contrib. However, I wouldn't like to make the Sightly core depend on Sling Models because not all projects that use Sightly also use models (although they're a really cool feature) and vice-versa. In this regard I think we should follow the general consensus of creating another bundle. Do you think it makes sense? Improve JavaUseProvider to not fall back to a simple Pojo instantiation in case a Java class with @Model annotation cannot be instantiated -- Key: SLING-4447 URL: https://issues.apache.org/jira/browse/SLING-4447 Project: Sling Issue Type: Improvement Components: Scripting Affects Versions: Scripting Sightly Engine 1.0.0 Reporter: Konrad Windszus Assignee: Konrad Windszus Fix For: Sling Models Impl 1.2.0 Attachments: SLING-4447-v01.patch Currently in case a Java class is a Sling Model (i.e. has the Model annotation) and cannot be instantiated (e.g. required injections not possible) Sightly falls back to instantiate those as simple Pojos. This is never good, since a lot of NullPointerException might happen because all injections have not been performed then. Therefore in the following code should be used instead {code} if (modelFactory.isModelClass(resource, cls)) { if (modelFactory.canCreateFromAdaptable(resource, cls)) { obj = modelFactory.createModel(resource, cls); } else if (modelFactory.canCreateFromAdaptable(request, cls)) { obj = modelFactory.createModel(request, cls); } else { throw new IllegalStateException(Could not adapt the given Sling Model from neither resource nor request: + cls); } } {code} That way, exceptions would be propagated in case a Sling model cannot be instantiated and developers more easily see why the Sling Model does not work (instead of running into NullPointerExceptions in their model because it was instantiated as simple Pojo) -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (SLING-4447) Improve JavaUseProvider to not fall back to a simple Pojo instantiation in case a Java class with @Model annotation cannot be instantiated
[ https://issues.apache.org/jira/browse/SLING-4447?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=14482777#comment-14482777 ] Konrad Windszus commented on SLING-4447: [~radu.cotescu] Thanks for that hint, I am gonna remove that dependency. Since Sling Models is not in contrib but Sightly is, what do you think about adding that UseProvider to the Sightly bundle (then we could use the UseProviderUtils class). Of course that would only work after we have a Sling Models 1.2 release and would require a dependency from the Sightly bundle to Sling Models API, but I don't think that would do any harm. If you don't want to add that dependency I will put that ModelsUseProvider to a dedicated bundle in contrib, but in that case it would be great if the UseProviderUtils would be exposed from Sightly. Improve JavaUseProvider to not fall back to a simple Pojo instantiation in case a Java class with @Model annotation cannot be instantiated -- Key: SLING-4447 URL: https://issues.apache.org/jira/browse/SLING-4447 Project: Sling Issue Type: Improvement Components: Scripting Affects Versions: Scripting Sightly Engine 1.0.0 Reporter: Konrad Windszus Assignee: Konrad Windszus Fix For: Sling Models Impl 1.2.0 Attachments: SLING-4447-v01.patch Currently in case a Java class is a Sling Model (i.e. has the Model annotation) and cannot be instantiated (e.g. required injections not possible) Sightly falls back to instantiate those as simple Pojos. This is never good, since a lot of NullPointerException might happen because all injections have not been performed then. Therefore in the following code should be used instead {code} if (modelFactory.isModelClass(resource, cls)) { if (modelFactory.canCreateFromAdaptable(resource, cls)) { obj = modelFactory.createModel(resource, cls); } else if (modelFactory.canCreateFromAdaptable(request, cls)) { obj = modelFactory.createModel(request, cls); } else { throw new IllegalStateException(Could not adapt the given Sling Model from neither resource nor request: + cls); } } {code} That way, exceptions would be propagated in case a Sling model cannot be instantiated and developers more easily see why the Sling Model does not work (instead of running into NullPointerExceptions in their model because it was instantiated as simple Pojo) -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (SLING-4447) Improve JavaUseProvider to not fall back to a simple Pojo instantiation in case a Java class with @Model annotation cannot be instantiated
[ https://issues.apache.org/jira/browse/SLING-4447?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=14481332#comment-14481332 ] Radu Cotescu commented on SLING-4447: - Besides [~sseif...@pro-vision.de]'s suggestion you should also clean the code in order to not use implementation classes from Sightly \[0\]\[1\]. \[0\] - https://github.com/apache/sling/blob/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/sightly/ModelFactoryUseProvider.java#L34 \[1\] - https://github.com/apache/sling/blob/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/sightly/ModelFactoryUseProvider.java#L80 Improve JavaUseProvider to not fall back to a simple Pojo instantiation in case a Java class with @Model annotation cannot be instantiated -- Key: SLING-4447 URL: https://issues.apache.org/jira/browse/SLING-4447 Project: Sling Issue Type: Improvement Components: Scripting Affects Versions: Scripting Sightly Engine 1.0.0 Reporter: Konrad Windszus Assignee: Konrad Windszus Fix For: Sling Models Impl 1.2.0 Attachments: SLING-4447-v01.patch Currently in case a Java class is a Sling Model (i.e. has the Model annotation) and cannot be instantiated (e.g. required injections not possible) Sightly falls back to instantiate those as simple Pojos. This is never good, since a lot of NullPointerException might happen because all injections have not been performed then. Therefore in the following code should be used instead {code} if (modelFactory.isModelClass(resource, cls)) { if (modelFactory.canCreateFromAdaptable(resource, cls)) { obj = modelFactory.createModel(resource, cls); } else if (modelFactory.canCreateFromAdaptable(request, cls)) { obj = modelFactory.createModel(request, cls); } else { throw new IllegalStateException(Could not adapt the given Sling Model from neither resource nor request: + cls); } } {code} That way, exceptions would be propagated in case a Sling model cannot be instantiated and developers more easily see why the Sling Model does not work (instead of running into NullPointerExceptions in their model because it was instantiated as simple Pojo) -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (SLING-4447) Improve JavaUseProvider to not fall back to a simple Pojo instantiation in case a Java class with @Model annotation cannot be instantiated
[ https://issues.apache.org/jira/browse/SLING-4447?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=14338328#comment-14338328 ] Konrad Windszus commented on SLING-4447: I applied a slightly modified version in rev 1662434 incorporating the feedback from [~radu.cotescu]. Regarding the optional import, that is already done by setting the maven dependency to optional (that will force the maven-bundle-plugin to create optional package-import statements). Improve JavaUseProvider to not fall back to a simple Pojo instantiation in case a Java class with @Model annotation cannot be instantiated -- Key: SLING-4447 URL: https://issues.apache.org/jira/browse/SLING-4447 Project: Sling Issue Type: Improvement Components: Scripting Affects Versions: Scripting Sightly Engine 1.0.0 Reporter: Konrad Windszus Assignee: Konrad Windszus Fix For: Sling Models Impl 1.2.0 Attachments: SLING-4447-v01.patch Currently in case a Java class is a Sling Model (i.e. has the Model annotation) and cannot be instantiated (e.g. required injections not possible) Sightly falls back to instantiate those as simple Pojos. This is never good, since a lot of NullPointerException might happen because all injections have not been performed then. Therefore in the following code should be used instead {code} if (modelFactory.isModelClass(resource, cls)) { if (modelFactory.canCreateFromAdaptable(resource, cls)) { obj = modelFactory.createModel(resource, cls); } else if (modelFactory.canCreateFromAdaptable(request, cls)) { obj = modelFactory.createModel(request, cls); } else { throw new IllegalStateException(Could not adapt the given Sling Model from neither resource nor request: + cls); } } {code} That way, exceptions would be propagated in case a Sling model cannot be instantiated and developers more easily see why the Sling Model does not work (instead of running into NullPointerExceptions in their model because it was instantiated as simple Pojo) -- This message was sent by Atlassian JIRA (v6.3.4#6332)