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

Carsten Ziegeler commented on SLING-12757:
------------------------------------------

We can't change the contract of the Resource interface - or at least we should 
not. There is nearly no code out there expecting getName() or most of the 
methods to throw an exception.
I think we introduced throwing exceptions in AbstractResource due to a series 
of refactorings and as these are unchecked exceptions this went through 
unnoticed.
It seems that ResourceUtil.getName() is doing to much - it should extract the 
name from the path which is just the last path segment, but it is also trying 
to normalize the path - which in most cases is unnecessary to get the name.

> AbstractResource.getName() can throw exceptions
> -----------------------------------------------
>
>                 Key: SLING-12757
>                 URL: https://issues.apache.org/jira/browse/SLING-12757
>             Project: Sling
>          Issue Type: Task
>          Components: API
>    Affects Versions: API 2.27.6
>            Reporter: Joerg Hoh
>            Priority: Major
>
> {{AbstractResource.getName()}} can throw both a NPE and an 
> IllegalArgumentException, because these can thrown by 
> {{ResourceUtil.getName()}}, although this is not documented.
> We have 2 options:
> # keep the existing implementation and adjust the API doc, that it can throw 
> these exceptions.
> # stick to the existing API doc and catch&log these 2 exceptions. This leaves 
> the question what to return in this case.
> WDYT?



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to