[ 
https://issues.apache.org/jira/browse/SLING-3714?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14048780#comment-14048780
 ] 

Konrad Windszus edited comment on SLING-3714 at 7/1/14 11:51 AM:
-----------------------------------------------------------------

Idea from [~bdelacretaz] in 
http://www.mail-archive.com/dev@sling.apache.org/msg31261.html: Don't change 
the API of the Adapter nor of the AdapterFactory, but only touch the 
AdapterManagerImpl 
(https://github.com/apache/sling/blob/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterManagerImpl.java)
 to be able to deal with a parametrization like 
{code}
Foo f = someObject.adaptTo(RequireAdapter<Foo>.class));
{code}

In that case 
a) RuntimeExceptions from AdapterFactories should not be caught (already the 
case)
b) Instead of returning null if no AdapterFactory can be found an exception 
should be thrown

In all other cases
c) RuntimeExceptions should be caught and logged (still to be decided on what 
level)
d) null is returned if adaptation was not successfull (for whatever reason)

In addition to that code change the javadoc of AdapterFactory 
(https://github.com/apache/sling/blob/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/AdapterFactory.java)
 should be extended to say that RuntimeExceptions should be thrown, if the 
adaptation is not possible for some technical reasons.


was (Author: kwin):
Idea from [~bdelacretaz]: Don't change the API of the Adapter nor of the 
AdapterFactory, but only touch the AdapterManagerImpl 
(https://github.com/apache/sling/blob/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterManagerImpl.java)
 to be able to deal with a parametrization like 
{code}
Foo f = someObject.adaptTo(RequireAdapter<Foo>.class));
{code}

In that case 
a) RuntimeExceptions from AdapterFactories should not be caught (already the 
case)
b) Instead of returning null if no AdapterFactory can be found an exception 
should be thrown

In all other cases
c) RuntimeExceptions should be caught and logged (still to be decided on what 
level)
d) null is returned if adaptation was not successfull (for whatever reason)

In addition to that code change the javadoc of AdapterFactory 
(https://github.com/apache/sling/blob/trunk/bundles/api/src/main/java/org/apache/sling/api/adapter/AdapterFactory.java)
 should be extended to say that RuntimeExceptions should be thrown, if the 
adaptation is not possible for some technical reasons.

> Allow for a caller to request a non-null response from adaptTo()
> ----------------------------------------------------------------
>
>                 Key: SLING-3714
>                 URL: https://issues.apache.org/jira/browse/SLING-3714
>             Project: Sling
>          Issue Type: Improvement
>            Reporter: Justin Edelson
>
> See SLING-3709 for a Sling Models-specific request. As I commented there, I 
> think this makes more sense as a core change to the Adaptable interface.
> One option:
> resource.adaptTo(Result<Node>.class)
> Which returns a Result object, which has an API like:
> interface Result<T> {
> boolean isSuccess();
> T getObject();
> List<Error> getErrors();
> }



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to