You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Konrad Windszus <ko...@gmx.de> on 2016/06/01 11:29:21 UTC
Resource.getParent() on NonExistingResource
Hi,
I have a question around the getParent() method on a NonExistingResource.
Currently it returns null in case the parent is also a non existing resource.
According to the javadoc of Resource.getParent() this is kind of unexpected, because it states (https://github.com/apache/sling/blob/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/Resource.java#L89)
...
Returns the parent resource or <code>null</code> if this resource
* represents the root of the resource tree.
...
Derived from that I would assume that a NonExistingResource would also return a NonExistingResource as result of getParent() in case the parent does not exist either instead of returning null (which it does right now).
In case the behaviour of returning null is deliberate, we should clarify the javadoc of Resource.getParent() with the additional conditions when this method may return null.
WDYT?
Thanks,
Konrad
Re: Resource.getParent() on NonExistingResource
Posted by Konrad Windszus <ko...@gmx.de>.
I only propose to change getParent() on NonExistingResource. Right now we have the situation that getParent() would just return the wrong NonExistingResource! So what we could do is to rely on resolve() as a fallback in case the regular way does not succeed. That would not make things any worse than they currently are. For real resources the getParent() handling would not be touched at all.
But I know that even the solution of relying on RR.resolve(String) is not optimal, as the resource resolver mapping is only 100% functional in case you also consider the request (which you don't have at hand at that point in time).
Maybe someone else has another good idea on how to solve this...
Thanks,
Konrad
> On 10 Jun 2016, at 16:24, Rob Ryan <rr...@adobe.com> wrote:
>
> Regardless of what other problem may exist; involving resolve() in
> getParent() isn't a solution.
>
> Resolve() operates on _URI_ paths. Not on resource paths. So proposing to
> involve resolve() in an implementation of getParent() doesn't make sense.
>
> Resolve() makes special considerations of some constructs:
> _foo_bar to mean foo:bar. But a resource path could legitimately have
> _foo_bar as a component.
>
> /* : star resource handling
>
>
> getParent() would likely be broken if it involved resolve() in such cases.
>
>
> -Rob
>
> On 6/10/16, 12:12 AM, "Konrad Windszus" <ko...@gmx.de> wrote:
>
>> There is one related problem with mapping:
>>
>> Consider the case you have a resource resolver mapping from "/content/"
>> to "/". In the underlying repository you have a resource in
>> "/content/existingParent".
>>
>> Now it might happen that a NonExistingResource is resolved for path
>> "/existingParent/nonExistingResource". Since this is pointing towards a
>> non-existing resource the mapping is not active (i.e. the path will not
>> contain "/content"). So you end up with a NonExistingResource with path
>> "/existingParent/nonExistingResource".
>> Now you call getParent() on this resource.
>>
>> You would expect to end up with an existing resource in
>> "/content/existingParent" (because that path does exist in the
>> repository). Unfortunately due to the logic in
>> AbstractResource.getParent() this just calls ResourceResolver.getParent()
>> which will not use ResourceResolver.resolve(...) but rather
>> ResourceResolver.getResource(...) internally. So the mapping is not
>> considered here. Therefore no resource is found at "/existingParent",
>> although it does exist at "/content/existingParent".
>>
>> This is unexpected and wrong in my opinion. So the NonExistingResource
>> should not rely on AbstractResource.getParent() at all, but rather use
>> its own implementation relying on ResourceResolver.resolve(...). WDYT?
>>
>> Thanks,
>> Konrad
>>
>>
>>> On 02 Jun 2016, at 14:48, Konrad Windszus <ko...@gmx.de> wrote:
>>>
>>> Thanks for the input.
>>> I created https://issues.apache.org/jira/browse/SLING-5757 for tracking
>>> that and I am going to propose a patch in there.
>>>
>>> What about SyntheticResources which are not NonExistingResources? If we
>>> would follow the same approach as for NonExistingResources the question
>>> is, with which resource type the non-existing parent resource should be
>>> created? Or should a SyntheticResource (which is not a
>>> NonExistingResource) return a NonExistingResource for getParent()
>>> instead in that case?
>>>
>>> Konrad
>>>
>>>
>>>> On 02 Jun 2016, at 13:47, Daniel Klco <dk...@apache.org> wrote:
>>>>
>>>> I would imagine that the only thing this would change is to make a
>>>> small
>>>> number of null checks irrelevant.
>>>>
>>>> +1 for making the behavior more consistent, however, the JavaDocs and
>>>> release notes should be explicit about this change.
>>>>
>>>> On Thu, Jun 2, 2016 at 4:45 AM, Georg Henzler <sl...@ghenzler.de>
>>>> wrote:
>>>>
>>>>> Hi Konrad,
>>>>>
>>>>> +1 for making the behaviour of NonExistingResource more consistent - I
>>>>> personally can't think of any places this would break existing code.
>>>>>
>>>>> Regards
>>>>> Georg
>>>>>
>>>>>
>>>>>
>>>>> On 2016-06-01 15:09, Konrad Windszus wrote:
>>>>>
>>>>>> Hi Robert,
>>>>>> thanks for your input.
>>>>>>
>>>>>>
>>>>>>> I am not sure whether this would confuse existing clients though...
>>>>>>>
>>>>>>
>>>>>> I am also a bit worried about that but the only example I could think
>>>>>> of is a code trying to create the parent nodes or collecting the
>>>>>> non-existing ones by checking getParent() for null.
>>>>>>
>>>>>> This would be pretty bad style IMHO therefore I would deliberately be
>>>>>> willing to break that code. I wonder what do others think about
>>>>>> changing the semantics of getParent() for NonExistingResource and
>>>>>> probably also SyntheticResource.
>>>>>> Konrad
>>>>>>
>>>>>
>>>>>
>>>
>>
>
Re: Resource.getParent() on NonExistingResource
Posted by Rob Ryan <rr...@adobe.com>.
Regardless of what other problem may exist; involving resolve() in
getParent() isn't a solution.
Resolve() operates on _URI_ paths. Not on resource paths. So proposing to
involve resolve() in an implementation of getParent() doesn't make sense.
Resolve() makes special considerations of some constructs:
_foo_bar to mean foo:bar. But a resource path could legitimately have
_foo_bar as a component.
/* : star resource handling
getParent() would likely be broken if it involved resolve() in such cases.
-Rob
On 6/10/16, 12:12 AM, "Konrad Windszus" <ko...@gmx.de> wrote:
>There is one related problem with mapping:
>
>Consider the case you have a resource resolver mapping from "/content/"
>to "/". In the underlying repository you have a resource in
>"/content/existingParent".
>
>Now it might happen that a NonExistingResource is resolved for path
>"/existingParent/nonExistingResource". Since this is pointing towards a
>non-existing resource the mapping is not active (i.e. the path will not
>contain "/content"). So you end up with a NonExistingResource with path
>"/existingParent/nonExistingResource".
>Now you call getParent() on this resource.
>
>You would expect to end up with an existing resource in
>"/content/existingParent" (because that path does exist in the
>repository). Unfortunately due to the logic in
>AbstractResource.getParent() this just calls ResourceResolver.getParent()
>which will not use ResourceResolver.resolve(...) but rather
>ResourceResolver.getResource(...) internally. So the mapping is not
>considered here. Therefore no resource is found at "/existingParent",
>although it does exist at "/content/existingParent".
>
>This is unexpected and wrong in my opinion. So the NonExistingResource
>should not rely on AbstractResource.getParent() at all, but rather use
>its own implementation relying on ResourceResolver.resolve(...). WDYT?
>
>Thanks,
>Konrad
>
>
>> On 02 Jun 2016, at 14:48, Konrad Windszus <ko...@gmx.de> wrote:
>>
>> Thanks for the input.
>> I created https://issues.apache.org/jira/browse/SLING-5757 for tracking
>>that and I am going to propose a patch in there.
>>
>> What about SyntheticResources which are not NonExistingResources? If we
>>would follow the same approach as for NonExistingResources the question
>>is, with which resource type the non-existing parent resource should be
>>created? Or should a SyntheticResource (which is not a
>>NonExistingResource) return a NonExistingResource for getParent()
>>instead in that case?
>>
>> Konrad
>>
>>
>>> On 02 Jun 2016, at 13:47, Daniel Klco <dk...@apache.org> wrote:
>>>
>>> I would imagine that the only thing this would change is to make a
>>>small
>>> number of null checks irrelevant.
>>>
>>> +1 for making the behavior more consistent, however, the JavaDocs and
>>> release notes should be explicit about this change.
>>>
>>> On Thu, Jun 2, 2016 at 4:45 AM, Georg Henzler <sl...@ghenzler.de>
>>>wrote:
>>>
>>>> Hi Konrad,
>>>>
>>>> +1 for making the behaviour of NonExistingResource more consistent - I
>>>> personally can't think of any places this would break existing code.
>>>>
>>>> Regards
>>>> Georg
>>>>
>>>>
>>>>
>>>> On 2016-06-01 15:09, Konrad Windszus wrote:
>>>>
>>>>> Hi Robert,
>>>>> thanks for your input.
>>>>>
>>>>>
>>>>>> I am not sure whether this would confuse existing clients though...
>>>>>>
>>>>>
>>>>> I am also a bit worried about that but the only example I could think
>>>>> of is a code trying to create the parent nodes or collecting the
>>>>> non-existing ones by checking getParent() for null.
>>>>>
>>>>> This would be pretty bad style IMHO therefore I would deliberately be
>>>>> willing to break that code. I wonder what do others think about
>>>>> changing the semantics of getParent() for NonExistingResource and
>>>>> probably also SyntheticResource.
>>>>> Konrad
>>>>>
>>>>
>>>>
>>
>
Re: Resource.getParent() on NonExistingResource
Posted by Michael Dürig <md...@apache.org>.
On 10.6.16 9:26 , Carsten Ziegeler wrote:
> I think calling resolve() for traversal is totally unexpected. Now
> looking at this, I'm really wondering if it was a good idea to implement
> getParent on NonExistingResource. Let the client deal with it instead of
> adding complex special cases.
FWIW: in Oak we have a similar situation with Tree instances. Retrieving
a non existing child from a Tree instance returns a Tree instance whose
.exists() method returns false. Calling .getParent() on that non
existing Tree instance returns the original parent Tree instance from
which it was acquired.
Michael
>
> Carsten
>
> Konrad Windszus wrote
>> There is one related problem with mapping:
>>
>> Consider the case you have a resource resolver mapping from "/content/" to "/". In the underlying repository you have a resource in "/content/existingParent".
>>
>> Now it might happen that a NonExistingResource is resolved for path "/existingParent/nonExistingResource". Since this is pointing towards a non-existing resource the mapping is not active (i.e. the path will not contain "/content"). So you end up with a NonExistingResource with path "/existingParent/nonExistingResource".
>> Now you call getParent() on this resource.
>>
>> You would expect to end up with an existing resource in "/content/existingParent" (because that path does exist in the repository). Unfortunately due to the logic in AbstractResource.getParent() this just calls ResourceResolver.getParent() which will not use ResourceResolver.resolve(...) but rather ResourceResolver.getResource(...) internally. So the mapping is not considered here. Therefore no resource is found at "/existingParent", although it does exist at "/content/existingParent".
>>
>> This is unexpected and wrong in my opinion. So the NonExistingResource should not rely on AbstractResource.getParent() at all, but rather use its own implementation relying on ResourceResolver.resolve(...). WDYT?
>>
>> Thanks,
>> Konrad
>>
>>
>>> On 02 Jun 2016, at 14:48, Konrad Windszus <ko...@gmx.de> wrote:
>>>
>>> Thanks for the input.
>>> I created https://issues.apache.org/jira/browse/SLING-5757 for tracking that and I am going to propose a patch in there.
>>>
>>> What about SyntheticResources which are not NonExistingResources? If we would follow the same approach as for NonExistingResources the question is, with which resource type the non-existing parent resource should be created? Or should a SyntheticResource (which is not a NonExistingResource) return a NonExistingResource for getParent() instead in that case?
>>>
>>> Konrad
>>>
>>>
>>>> On 02 Jun 2016, at 13:47, Daniel Klco <dk...@apache.org> wrote:
>>>>
>>>> I would imagine that the only thing this would change is to make a small
>>>> number of null checks irrelevant.
>>>>
>>>> +1 for making the behavior more consistent, however, the JavaDocs and
>>>> release notes should be explicit about this change.
>>>>
>>>> On Thu, Jun 2, 2016 at 4:45 AM, Georg Henzler <sl...@ghenzler.de> wrote:
>>>>
>>>>> Hi Konrad,
>>>>>
>>>>> +1 for making the behaviour of NonExistingResource more consistent - I
>>>>> personally can't think of any places this would break existing code.
>>>>>
>>>>> Regards
>>>>> Georg
>>>>>
>>>>>
>>>>>
>>>>> On 2016-06-01 15:09, Konrad Windszus wrote:
>>>>>
>>>>>> Hi Robert,
>>>>>> thanks for your input.
>>>>>>
>>>>>>
>>>>>>> I am not sure whether this would confuse existing clients though...
>>>>>>>
>>>>>>
>>>>>> I am also a bit worried about that but the only example I could think
>>>>>> of is a code trying to create the parent nodes or collecting the
>>>>>> non-existing ones by checking getParent() for null.
>>>>>>
>>>>>> This would be pretty bad style IMHO therefore I would deliberately be
>>>>>> willing to break that code. I wonder what do others think about
>>>>>> changing the semantics of getParent() for NonExistingResource and
>>>>>> probably also SyntheticResource.
>>>>>> Konrad
>>>>>>
>>>>>
>>>>>
>>>
>>
>>
>
>
>
>
Re: Resource.getParent() on NonExistingResource
Posted by Julian Sedding <js...@gmail.com>.
IMHO your NonExistingResource or SynthetricResource should already
have the correct absolute path. As Rob noted, RR.resolve() is about
resolving URIs to Resources. Once you are navigating Resources (e.g.
getParent()), no more resolve() calls should happen.
From my point of view the problem is that the mapping (/ -> /content/)
is not applied when the URI is resolved. I would expect that you get:
nonExistingResource.getPath() ->
"/content/existingParent/nonExistingResource" (IMO getting
"/existingParent/nonExistingResource" here is a bug)
nonExistingResource.getParent().getPath() -> "/content/existingParent" (exists)
What would be involved in fixing the (IMO) correct resolution of the
"nonExistingResource"?
Regards
Julian
On Fri, Jun 10, 2016 at 5:12 PM, Konrad Windszus <ko...@gmx.de> wrote:
> I am talking about https://github.com/apache/sling/blob/c9e59667d8f9cd698bc33a51f3e6a22e85d4a952/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/ResourceRuntimeExtension.java#L254 <https://github.com/apache/sling/blob/c9e59667d8f9cd698bc33a51f3e6a22e85d4a952/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/ResourceRuntimeExtension.java#L254> here.
> The best would be if the SyntheticResource would optionally get a list of possible resolved resource locations. If we add another constructor taking an additional List<String> with possible resolved repository paths we would be able to consider that list in the getParent().
> That way we would not directly rely on ResourceResolver.resolve() within getParent() but just try getParent() for the different possible repository paths until we find a matching one, or if we don't find a matching one return a NonExistingResource(), again being feeded with the same list of possible resolved repository paths.
> WDYT?
> Konrad
>
>
>> On 10 Jun 2016, at 10:13, Carsten Ziegeler <cz...@apache.org> wrote:
>>
>> Konrad Windszus wrote
>>> My use case is AEM:
>>> I have an existing page containing some components (each one encapsulated in dedicated child resources).
>>> Now the underlying template in AEM is extended (i.e. new fixed components have been added). For each of those a child resource is necessary, which does not exist yet on older pages (being created at a point in time, where the template did not have that component yet).
>>>
>>> In Sightly we include those new components via data-sly-use with an explicit resourceType. Sightly will first try to get the child resource with that path. If it does not exist yet it will create a SyntheticResource with the given resource type.
>>> For example to get the cloud service configuration we would need to get the (existing) container AEM page for the SyntheticResource. This currently fails, because of the issues mentioned.
>>>
>>> If this would work, the component would be rendered fine (even acting on a SyntheticResource).
>>
>> Ok, so I guess this can be easily solved in Sightly as this sounds to me
>> like a Sightly use case.
>>
>> Carsten
>> --
>> Carsten Ziegeler
>> Adobe Research Switzerland
>> cziegeler@apache.org
>
Re: Resource.getParent() on NonExistingResource
Posted by Konrad Windszus <ko...@gmx.de>.
I am talking about https://github.com/apache/sling/blob/c9e59667d8f9cd698bc33a51f3e6a22e85d4a952/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/ResourceRuntimeExtension.java#L254 <https://github.com/apache/sling/blob/c9e59667d8f9cd698bc33a51f3e6a22e85d4a952/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/ResourceRuntimeExtension.java#L254> here.
The best would be if the SyntheticResource would optionally get a list of possible resolved resource locations. If we add another constructor taking an additional List<String> with possible resolved repository paths we would be able to consider that list in the getParent().
That way we would not directly rely on ResourceResolver.resolve() within getParent() but just try getParent() for the different possible repository paths until we find a matching one, or if we don't find a matching one return a NonExistingResource(), again being feeded with the same list of possible resolved repository paths.
WDYT?
Konrad
> On 10 Jun 2016, at 10:13, Carsten Ziegeler <cz...@apache.org> wrote:
>
> Konrad Windszus wrote
>> My use case is AEM:
>> I have an existing page containing some components (each one encapsulated in dedicated child resources).
>> Now the underlying template in AEM is extended (i.e. new fixed components have been added). For each of those a child resource is necessary, which does not exist yet on older pages (being created at a point in time, where the template did not have that component yet).
>>
>> In Sightly we include those new components via data-sly-use with an explicit resourceType. Sightly will first try to get the child resource with that path. If it does not exist yet it will create a SyntheticResource with the given resource type.
>> For example to get the cloud service configuration we would need to get the (existing) container AEM page for the SyntheticResource. This currently fails, because of the issues mentioned.
>>
>> If this would work, the component would be rendered fine (even acting on a SyntheticResource).
>
> Ok, so I guess this can be easily solved in Sightly as this sounds to me
> like a Sightly use case.
>
> Carsten
> --
> Carsten Ziegeler
> Adobe Research Switzerland
> cziegeler@apache.org
Re: Resource.getParent() on NonExistingResource
Posted by Carsten Ziegeler <cz...@apache.org>.
Konrad Windszus wrote
> My use case is AEM:
> I have an existing page containing some components (each one encapsulated in dedicated child resources).
> Now the underlying template in AEM is extended (i.e. new fixed components have been added). For each of those a child resource is necessary, which does not exist yet on older pages (being created at a point in time, where the template did not have that component yet).
>
> In Sightly we include those new components via data-sly-use with an explicit resourceType. Sightly will first try to get the child resource with that path. If it does not exist yet it will create a SyntheticResource with the given resource type.
> For example to get the cloud service configuration we would need to get the (existing) container AEM page for the SyntheticResource. This currently fails, because of the issues mentioned.
>
> If this would work, the component would be rendered fine (even acting on a SyntheticResource).
Ok, so I guess this can be easily solved in Sightly as this sounds to me
like a Sightly use case.
Carsten
--
Carsten Ziegeler
Adobe Research Switzerland
cziegeler@apache.org
Re: Resource.getParent() on NonExistingResource
Posted by Konrad Windszus <ko...@gmx.de>.
My use case is AEM:
I have an existing page containing some components (each one encapsulated in dedicated child resources).
Now the underlying template in AEM is extended (i.e. new fixed components have been added). For each of those a child resource is necessary, which does not exist yet on older pages (being created at a point in time, where the template did not have that component yet).
In Sightly we include those new components via data-sly-use with an explicit resourceType. Sightly will first try to get the child resource with that path. If it does not exist yet it will create a SyntheticResource with the given resource type.
For example to get the cloud service configuration we would need to get the (existing) container AEM page for the SyntheticResource. This currently fails, because of the issues mentioned.
If this would work, the component would be rendered fine (even acting on a SyntheticResource).
Konrad
> On 10 Jun 2016, at 09:48, Carsten Ziegeler <cz...@apache.org> wrote:
>
> Konrad Windszus wrote
>> This is complex to solve for the client (and kind of unexpected that this is not working).
>> So what speaks against supporting this use case properly in Sling.
>> Maybe you can elaborate a bit on
>>> I think calling resolve() for traversal is totally unexpected.
>>
>> IMHO the complex cases should be nicely covered by Sling (instead of adding that burden to each client).
>> Of course calling resolve() would only be done for the NonExistingResource (and maybe the SyntheticResource). The handling for regular existing resources should stay exactly as is (i.e. not relying on resolve() at all).
>>
>> I meanwhile opened https://issues.apache.org/jira/browse/SLING-5773 <https://issues.apache.org/jira/browse/SLING-5773> about this problem.
>>
>
> The only place where you get a NonExistingResource is the resolve
> method, getResource returns null. As this is known, whoever is calling
> resolve() can check whether the returned resource is a
> NonExistingResource, then call resolve with the parent path or whatever.
>
> What is your use case?
>
> Regards
> Carsten
> --
> Carsten Ziegeler
> Adobe Research Switzerland
> cziegeler@apache.org
Re: Resource.getParent() on NonExistingResource
Posted by Carsten Ziegeler <cz...@apache.org>.
Konrad Windszus wrote
> This is complex to solve for the client (and kind of unexpected that this is not working).
> So what speaks against supporting this use case properly in Sling.
> Maybe you can elaborate a bit on
>> I think calling resolve() for traversal is totally unexpected.
>
> IMHO the complex cases should be nicely covered by Sling (instead of adding that burden to each client).
> Of course calling resolve() would only be done for the NonExistingResource (and maybe the SyntheticResource). The handling for regular existing resources should stay exactly as is (i.e. not relying on resolve() at all).
>
> I meanwhile opened https://issues.apache.org/jira/browse/SLING-5773 <https://issues.apache.org/jira/browse/SLING-5773> about this problem.
>
The only place where you get a NonExistingResource is the resolve
method, getResource returns null. As this is known, whoever is calling
resolve() can check whether the returned resource is a
NonExistingResource, then call resolve with the parent path or whatever.
What is your use case?
Regards
Carsten
--
Carsten Ziegeler
Adobe Research Switzerland
cziegeler@apache.org
Re: Resource.getParent() on NonExistingResource
Posted by Konrad Windszus <ko...@gmx.de>.
This is complex to solve for the client (and kind of unexpected that this is not working).
So what speaks against supporting this use case properly in Sling.
Maybe you can elaborate a bit on
> I think calling resolve() for traversal is totally unexpected.
IMHO the complex cases should be nicely covered by Sling (instead of adding that burden to each client).
Of course calling resolve() would only be done for the NonExistingResource (and maybe the SyntheticResource). The handling for regular existing resources should stay exactly as is (i.e. not relying on resolve() at all).
I meanwhile opened https://issues.apache.org/jira/browse/SLING-5773 <https://issues.apache.org/jira/browse/SLING-5773> about this problem.
Konrad
> On 10 Jun 2016, at 09:26, Carsten Ziegeler <cz...@apache.org> wrote:
>
> I think calling resolve() for traversal is totally unexpected. Now
> looking at this, I'm really wondering if it was a good idea to implement
> getParent on NonExistingResource. Let the client deal with it instead of
> adding complex special cases.
>
> Carsten
>
> Konrad Windszus wrote
>> There is one related problem with mapping:
>>
>> Consider the case you have a resource resolver mapping from "/content/" to "/". In the underlying repository you have a resource in "/content/existingParent".
>>
>> Now it might happen that a NonExistingResource is resolved for path "/existingParent/nonExistingResource". Since this is pointing towards a non-existing resource the mapping is not active (i.e. the path will not contain "/content"). So you end up with a NonExistingResource with path "/existingParent/nonExistingResource".
>> Now you call getParent() on this resource.
>>
>> You would expect to end up with an existing resource in "/content/existingParent" (because that path does exist in the repository). Unfortunately due to the logic in AbstractResource.getParent() this just calls ResourceResolver.getParent() which will not use ResourceResolver.resolve(...) but rather ResourceResolver.getResource(...) internally. So the mapping is not considered here. Therefore no resource is found at "/existingParent", although it does exist at "/content/existingParent".
>>
>> This is unexpected and wrong in my opinion. So the NonExistingResource should not rely on AbstractResource.getParent() at all, but rather use its own implementation relying on ResourceResolver.resolve(...). WDYT?
>>
>> Thanks,
>> Konrad
>>
>>
>>> On 02 Jun 2016, at 14:48, Konrad Windszus <ko...@gmx.de> wrote:
>>>
>>> Thanks for the input.
>>> I created https://issues.apache.org/jira/browse/SLING-5757 for tracking that and I am going to propose a patch in there.
>>>
>>> What about SyntheticResources which are not NonExistingResources? If we would follow the same approach as for NonExistingResources the question is, with which resource type the non-existing parent resource should be created? Or should a SyntheticResource (which is not a NonExistingResource) return a NonExistingResource for getParent() instead in that case?
>>>
>>> Konrad
>>>
>>>
>>>> On 02 Jun 2016, at 13:47, Daniel Klco <dk...@apache.org> wrote:
>>>>
>>>> I would imagine that the only thing this would change is to make a small
>>>> number of null checks irrelevant.
>>>>
>>>> +1 for making the behavior more consistent, however, the JavaDocs and
>>>> release notes should be explicit about this change.
>>>>
>>>> On Thu, Jun 2, 2016 at 4:45 AM, Georg Henzler <sl...@ghenzler.de> wrote:
>>>>
>>>>> Hi Konrad,
>>>>>
>>>>> +1 for making the behaviour of NonExistingResource more consistent - I
>>>>> personally can't think of any places this would break existing code.
>>>>>
>>>>> Regards
>>>>> Georg
>>>>>
>>>>>
>>>>>
>>>>> On 2016-06-01 15:09, Konrad Windszus wrote:
>>>>>
>>>>>> Hi Robert,
>>>>>> thanks for your input.
>>>>>>
>>>>>>
>>>>>>> I am not sure whether this would confuse existing clients though...
>>>>>>>
>>>>>>
>>>>>> I am also a bit worried about that but the only example I could think
>>>>>> of is a code trying to create the parent nodes or collecting the
>>>>>> non-existing ones by checking getParent() for null.
>>>>>>
>>>>>> This would be pretty bad style IMHO therefore I would deliberately be
>>>>>> willing to break that code. I wonder what do others think about
>>>>>> changing the semantics of getParent() for NonExistingResource and
>>>>>> probably also SyntheticResource.
>>>>>> Konrad
>>>>>>
>>>>>
>>>>>
>>>
>>
>>
>
>
>
> --
> Carsten Ziegeler
> Adobe Research Switzerland
> cziegeler@apache.org
Re: Resource.getParent() on NonExistingResource
Posted by Carsten Ziegeler <cz...@apache.org>.
I think calling resolve() for traversal is totally unexpected. Now
looking at this, I'm really wondering if it was a good idea to implement
getParent on NonExistingResource. Let the client deal with it instead of
adding complex special cases.
Carsten
Konrad Windszus wrote
> There is one related problem with mapping:
>
> Consider the case you have a resource resolver mapping from "/content/" to "/". In the underlying repository you have a resource in "/content/existingParent".
>
> Now it might happen that a NonExistingResource is resolved for path "/existingParent/nonExistingResource". Since this is pointing towards a non-existing resource the mapping is not active (i.e. the path will not contain "/content"). So you end up with a NonExistingResource with path "/existingParent/nonExistingResource".
> Now you call getParent() on this resource.
>
> You would expect to end up with an existing resource in "/content/existingParent" (because that path does exist in the repository). Unfortunately due to the logic in AbstractResource.getParent() this just calls ResourceResolver.getParent() which will not use ResourceResolver.resolve(...) but rather ResourceResolver.getResource(...) internally. So the mapping is not considered here. Therefore no resource is found at "/existingParent", although it does exist at "/content/existingParent".
>
> This is unexpected and wrong in my opinion. So the NonExistingResource should not rely on AbstractResource.getParent() at all, but rather use its own implementation relying on ResourceResolver.resolve(...). WDYT?
>
> Thanks,
> Konrad
>
>
>> On 02 Jun 2016, at 14:48, Konrad Windszus <ko...@gmx.de> wrote:
>>
>> Thanks for the input.
>> I created https://issues.apache.org/jira/browse/SLING-5757 for tracking that and I am going to propose a patch in there.
>>
>> What about SyntheticResources which are not NonExistingResources? If we would follow the same approach as for NonExistingResources the question is, with which resource type the non-existing parent resource should be created? Or should a SyntheticResource (which is not a NonExistingResource) return a NonExistingResource for getParent() instead in that case?
>>
>> Konrad
>>
>>
>>> On 02 Jun 2016, at 13:47, Daniel Klco <dk...@apache.org> wrote:
>>>
>>> I would imagine that the only thing this would change is to make a small
>>> number of null checks irrelevant.
>>>
>>> +1 for making the behavior more consistent, however, the JavaDocs and
>>> release notes should be explicit about this change.
>>>
>>> On Thu, Jun 2, 2016 at 4:45 AM, Georg Henzler <sl...@ghenzler.de> wrote:
>>>
>>>> Hi Konrad,
>>>>
>>>> +1 for making the behaviour of NonExistingResource more consistent - I
>>>> personally can't think of any places this would break existing code.
>>>>
>>>> Regards
>>>> Georg
>>>>
>>>>
>>>>
>>>> On 2016-06-01 15:09, Konrad Windszus wrote:
>>>>
>>>>> Hi Robert,
>>>>> thanks for your input.
>>>>>
>>>>>
>>>>>> I am not sure whether this would confuse existing clients though...
>>>>>>
>>>>>
>>>>> I am also a bit worried about that but the only example I could think
>>>>> of is a code trying to create the parent nodes or collecting the
>>>>> non-existing ones by checking getParent() for null.
>>>>>
>>>>> This would be pretty bad style IMHO therefore I would deliberately be
>>>>> willing to break that code. I wonder what do others think about
>>>>> changing the semantics of getParent() for NonExistingResource and
>>>>> probably also SyntheticResource.
>>>>> Konrad
>>>>>
>>>>
>>>>
>>
>
>
--
Carsten Ziegeler
Adobe Research Switzerland
cziegeler@apache.org
Re: Resource.getParent() on NonExistingResource
Posted by Konrad Windszus <ko...@gmx.de>.
There is one related problem with mapping:
Consider the case you have a resource resolver mapping from "/content/" to "/". In the underlying repository you have a resource in "/content/existingParent".
Now it might happen that a NonExistingResource is resolved for path "/existingParent/nonExistingResource". Since this is pointing towards a non-existing resource the mapping is not active (i.e. the path will not contain "/content"). So you end up with a NonExistingResource with path "/existingParent/nonExistingResource".
Now you call getParent() on this resource.
You would expect to end up with an existing resource in "/content/existingParent" (because that path does exist in the repository). Unfortunately due to the logic in AbstractResource.getParent() this just calls ResourceResolver.getParent() which will not use ResourceResolver.resolve(...) but rather ResourceResolver.getResource(...) internally. So the mapping is not considered here. Therefore no resource is found at "/existingParent", although it does exist at "/content/existingParent".
This is unexpected and wrong in my opinion. So the NonExistingResource should not rely on AbstractResource.getParent() at all, but rather use its own implementation relying on ResourceResolver.resolve(...). WDYT?
Thanks,
Konrad
> On 02 Jun 2016, at 14:48, Konrad Windszus <ko...@gmx.de> wrote:
>
> Thanks for the input.
> I created https://issues.apache.org/jira/browse/SLING-5757 for tracking that and I am going to propose a patch in there.
>
> What about SyntheticResources which are not NonExistingResources? If we would follow the same approach as for NonExistingResources the question is, with which resource type the non-existing parent resource should be created? Or should a SyntheticResource (which is not a NonExistingResource) return a NonExistingResource for getParent() instead in that case?
>
> Konrad
>
>
>> On 02 Jun 2016, at 13:47, Daniel Klco <dk...@apache.org> wrote:
>>
>> I would imagine that the only thing this would change is to make a small
>> number of null checks irrelevant.
>>
>> +1 for making the behavior more consistent, however, the JavaDocs and
>> release notes should be explicit about this change.
>>
>> On Thu, Jun 2, 2016 at 4:45 AM, Georg Henzler <sl...@ghenzler.de> wrote:
>>
>>> Hi Konrad,
>>>
>>> +1 for making the behaviour of NonExistingResource more consistent - I
>>> personally can't think of any places this would break existing code.
>>>
>>> Regards
>>> Georg
>>>
>>>
>>>
>>> On 2016-06-01 15:09, Konrad Windszus wrote:
>>>
>>>> Hi Robert,
>>>> thanks for your input.
>>>>
>>>>
>>>>> I am not sure whether this would confuse existing clients though...
>>>>>
>>>>
>>>> I am also a bit worried about that but the only example I could think
>>>> of is a code trying to create the parent nodes or collecting the
>>>> non-existing ones by checking getParent() for null.
>>>>
>>>> This would be pretty bad style IMHO therefore I would deliberately be
>>>> willing to break that code. I wonder what do others think about
>>>> changing the semantics of getParent() for NonExistingResource and
>>>> probably also SyntheticResource.
>>>> Konrad
>>>>
>>>
>>>
>
Re: Resource.getParent() on NonExistingResource
Posted by Konrad Windszus <ko...@gmx.de>.
Thanks for the input.
I created https://issues.apache.org/jira/browse/SLING-5757 for tracking that and I am going to propose a patch in there.
What about SyntheticResources which are not NonExistingResources? If we would follow the same approach as for NonExistingResources the question is, with which resource type the non-existing parent resource should be created? Or should a SyntheticResource (which is not a NonExistingResource) return a NonExistingResource for getParent() instead in that case?
Konrad
> On 02 Jun 2016, at 13:47, Daniel Klco <dk...@apache.org> wrote:
>
> I would imagine that the only thing this would change is to make a small
> number of null checks irrelevant.
>
> +1 for making the behavior more consistent, however, the JavaDocs and
> release notes should be explicit about this change.
>
> On Thu, Jun 2, 2016 at 4:45 AM, Georg Henzler <sl...@ghenzler.de> wrote:
>
>> Hi Konrad,
>>
>> +1 for making the behaviour of NonExistingResource more consistent - I
>> personally can't think of any places this would break existing code.
>>
>> Regards
>> Georg
>>
>>
>>
>> On 2016-06-01 15:09, Konrad Windszus wrote:
>>
>>> Hi Robert,
>>> thanks for your input.
>>>
>>>
>>>> I am not sure whether this would confuse existing clients though...
>>>>
>>>
>>> I am also a bit worried about that but the only example I could think
>>> of is a code trying to create the parent nodes or collecting the
>>> non-existing ones by checking getParent() for null.
>>>
>>> This would be pretty bad style IMHO therefore I would deliberately be
>>> willing to break that code. I wonder what do others think about
>>> changing the semantics of getParent() for NonExistingResource and
>>> probably also SyntheticResource.
>>> Konrad
>>>
>>
>>
Re: Resource.getParent() on NonExistingResource
Posted by Daniel Klco <dk...@apache.org>.
I would imagine that the only thing this would change is to make a small
number of null checks irrelevant.
+1 for making the behavior more consistent, however, the JavaDocs and
release notes should be explicit about this change.
On Thu, Jun 2, 2016 at 4:45 AM, Georg Henzler <sl...@ghenzler.de> wrote:
> Hi Konrad,
>
> +1 for making the behaviour of NonExistingResource more consistent - I
> personally can't think of any places this would break existing code.
>
> Regards
> Georg
>
>
>
> On 2016-06-01 15:09, Konrad Windszus wrote:
>
>> Hi Robert,
>> thanks for your input.
>>
>>
>>> I am not sure whether this would confuse existing clients though...
>>>
>>
>> I am also a bit worried about that but the only example I could think
>> of is a code trying to create the parent nodes or collecting the
>> non-existing ones by checking getParent() for null.
>>
>> This would be pretty bad style IMHO therefore I would deliberately be
>> willing to break that code. I wonder what do others think about
>> changing the semantics of getParent() for NonExistingResource and
>> probably also SyntheticResource.
>> Konrad
>>
>
>
Re: Resource.getParent() on NonExistingResource
Posted by Georg Henzler <sl...@ghenzler.de>.
Hi Konrad,
+1 for making the behaviour of NonExistingResource more consistent - I
personally can't think of any places this would break existing code.
Regards
Georg
On 2016-06-01 15:09, Konrad Windszus wrote:
> Hi Robert,
> thanks for your input.
>
>>
>> I am not sure whether this would confuse existing clients though...
>
> I am also a bit worried about that but the only example I could think
> of is a code trying to create the parent nodes or collecting the
> non-existing ones by checking getParent() for null.
>
> This would be pretty bad style IMHO therefore I would deliberately be
> willing to break that code. I wonder what do others think about
> changing the semantics of getParent() for NonExistingResource and
> probably also SyntheticResource.
> Konrad
Re: Resource.getParent() on NonExistingResource
Posted by Konrad Windszus <ko...@gmx.de>.
Hi Robert,
thanks for your input.
>
> I am not sure whether this would confuse existing clients though...
I am also a bit worried about that but the only example I could think of is a code trying to create the parent nodes or collecting the non-existing ones by checking getParent() for null.
This would be pretty bad style IMHO therefore I would deliberately be willing to break that code. I wonder what do others think about changing the semantics of getParent() for NonExistingResource and probably also SyntheticResource.
Konrad
Re: Resource.getParent() on NonExistingResource
Posted by Robert Munteanu <ro...@apache.org>.
Hi,
On Wed, 2016-06-01 at 13:29 +0200, Konrad Windszus wrote:
> Hi,
> I have a question around the getParent() method on a
> NonExistingResource.
> Currently it returns null in case the parent is also a non existing
> resource.
>
> According to the javadoc of Resource.getParent() this is kind of
> unexpected, because it states (https://github.com/apache/sling/blob/t
> runk/bundles/api/src/main/java/org/apache/sling/api/resource/Resource
> .java#L89)
> ...
> Returns the parent resource or <code>null</code> if this resource
> * represents the root of the resource tree.
> ...
> Derived from that I would assume that a NonExistingResource would
> also return a NonExistingResource as result of getParent() in case
> the parent does not exist either instead of returning null (which it
> does right now).
I would cautiously agree with this approach as it's more natural from
an API consumer point of view.
I am not sure whether this would confuse existing clients though...
Thanks,
Robert
>
> In case the behaviour of returning null is deliberate, we should
> clarify the javadoc of Resource.getParent() with the additional
> conditions when this method may return null.
> WDYT?
>
> Thanks,
> Konrad