[
https://issues.apache.org/jira/browse/SLING-11067?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Konrad Windszus updated SLING-11067:
------------------------------------
Description:
Currently URIProvider is not allowed to return null according to
https://github.com/apache/sling-org-apache-sling-api/blob/333fa20f07a1d42897c9e0b6253bec5dcedb3e0b/src/main/java/org/apache/sling/api/resource/external/URIProvider.java#L48.
This forces every URIProvider to throw an exception for the (pretty common)
case it cannot provide a URI for a resource.
As creating exceptions comes with quite some overhead, I would propose to
enhance that interface.
As just allowing null return values would be backwards-incompatible I would
propose to instead add a second method called {{Optional<URI>
getOptionalUriForResource(Resource, Scope, Operation)}} with a default
implementation which calls {{toUri(...)}} and properly catches and logs
IllegalArgumentExceptions. At the same time I would deprecate the existing
method {{toURI(...)}}.
Compare with the discussion at
https://lists.apache.org/thread/xfgmrxbv6n1k5y57v6kq9pxnkyr6hcyb
was:
Currently URIProvider is not allowed to return null according to
https://github.com/apache/sling-org-apache-sling-api/blob/333fa20f07a1d42897c9e0b6253bec5dcedb3e0b/src/main/java/org/apache/sling/api/resource/external/URIProvider.java#L48.
This forces every URIProvider to throw an exception for the (pretty common)
case it cannot provide a URI for a resource.
As creating exceptions comes with quite some overhead, I would propose to
enhance that interface.
As just allowing null return values would be backwards-incompatible I would
propose to instead add a second method called {{Optional<URI>
getOptionalUriForResource(Resource, Scope, Operation)}} with a default
implementation which calls {{toUri(...)}} and properly catches and logs
IllegalArgumentExceptions. At the same time I would deprecate the existing
method {{toURI(...)}}.
> Extend URIProvider to not rely on exceptions if URIs can not be provided for
> a resource
> ---------------------------------------------------------------------------------------
>
> Key: SLING-11067
> URL: https://issues.apache.org/jira/browse/SLING-11067
> Project: Sling
> Issue Type: Improvement
> Components: API
> Reporter: Konrad Windszus
> Priority: Major
>
> Currently URIProvider is not allowed to return null according to
> https://github.com/apache/sling-org-apache-sling-api/blob/333fa20f07a1d42897c9e0b6253bec5dcedb3e0b/src/main/java/org/apache/sling/api/resource/external/URIProvider.java#L48.
> This forces every URIProvider to throw an exception for the (pretty common)
> case it cannot provide a URI for a resource.
> As creating exceptions comes with quite some overhead, I would propose to
> enhance that interface.
> As just allowing null return values would be backwards-incompatible I would
> propose to instead add a second method called {{Optional<URI>
> getOptionalUriForResource(Resource, Scope, Operation)}} with a default
> implementation which calls {{toUri(...)}} and properly catches and logs
> IllegalArgumentExceptions. At the same time I would deprecate the existing
> method {{toURI(...)}}.
> Compare with the discussion at
> https://lists.apache.org/thread/xfgmrxbv6n1k5y57v6kq9pxnkyr6hcyb
--
This message was sent by Atlassian Jira
(v8.20.1#820001)