[ 
https://issues.apache.org/jira/browse/SLING-10918?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Konrad Windszus updated SLING-10918:
------------------------------------
    Description: 
For the following unit test 
{code}
@Rule
public final SlingContext context = new 
SlingContext(ResourceResolverType.JCR_MOCK);

@Test
    public void test() throws Exception {
        ResourceResolver resourceResolver = 
MockSling.newResourceResolver(context.bundleContext());
        MockSlingHttpServletRequest request = new 
MockSlingHttpServletRequest(resourceResolver, context.bundleContext());
        resourceResolver.getResource("/some/path");
....
}
{code}

I ran into the following NPE
{code}
java.lang.NullPointerException
        at 
org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProvider.getResource(JcrResourceProvider.java:320)
        at 
org.apache.sling.testing.mock.sling.RRMockResourceResolverWrapper.getResource(RRMockResourceResolverWrapper.java:66)
...
{code}

This is caused by 
https://github.com/apache/sling-org-apache-sling-testing-sling-mock/blob/b642cb54b9f69c6f6649e335e0f7ae8da58183c6/core/src/main/java/org/apache/sling/testing/mock/sling/RRMockResourceResolverWrapper.java#L113
 returning {{null}} (which seems fine according to the contract which states 
that {{null}}} might be returned and 
https://github.com/apache/sling-org-apache-sling-jcr-resource/blob/89bc0bb344d6c7f109f6e43ef5e87bda7c04d286/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java#L320
 unconditionally dereferencing it.

I raised https://lists.apache.org/thread/tss0dlhqss5pzhqz89brlgryb3s44gh8 to 
clarify whether JCR Resource Provider needs to be fixed as well.

  was:
I ran into the following NPE
{code}
java.lang.NullPointerException
        at 
org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProvider.getResource(JcrResourceProvider.java:320)
        at 
org.apache.sling.testing.mock.sling.RRMockResourceResolverWrapper.getResource(RRMockResourceResolverWrapper.java:66)
...
{code}

This is caused by 
https://github.com/apache/sling-org-apache-sling-testing-sling-mock/blob/b642cb54b9f69c6f6649e335e0f7ae8da58183c6/core/src/main/java/org/apache/sling/testing/mock/sling/RRMockResourceResolverWrapper.java#L113
 returning {{null}} (which seems fine according to the contract which states 
that {{null}}} might be returned and 
https://github.com/apache/sling-org-apache-sling-jcr-resource/blob/89bc0bb344d6c7f109f6e43ef5e87bda7c04d286/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java#L320
 unconditionally dereferencing it.

I raised https://lists.apache.org/thread/tss0dlhqss5pzhqz89brlgryb3s44gh8 to 
clarify whether JCR Resource Provider needs to be fixed as well.


> NPE in RRMockResourceResolverWrapper.getResource()
> --------------------------------------------------
>
>                 Key: SLING-10918
>                 URL: https://issues.apache.org/jira/browse/SLING-10918
>             Project: Sling
>          Issue Type: Bug
>          Components: Testing
>    Affects Versions: Testing Sling Mock 3.1.2
>            Reporter: Konrad Windszus
>            Priority: Major
>
> For the following unit test 
> {code}
> @Rule
> public final SlingContext context = new 
> SlingContext(ResourceResolverType.JCR_MOCK);
> @Test
>     public void test() throws Exception {
>         ResourceResolver resourceResolver = 
> MockSling.newResourceResolver(context.bundleContext());
>         MockSlingHttpServletRequest request = new 
> MockSlingHttpServletRequest(resourceResolver, context.bundleContext());
>         resourceResolver.getResource("/some/path");
> ....
> }
> {code}
> I ran into the following NPE
> {code}
> java.lang.NullPointerException
>       at 
> org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProvider.getResource(JcrResourceProvider.java:320)
>       at 
> org.apache.sling.testing.mock.sling.RRMockResourceResolverWrapper.getResource(RRMockResourceResolverWrapper.java:66)
> ...
> {code}
> This is caused by 
> https://github.com/apache/sling-org-apache-sling-testing-sling-mock/blob/b642cb54b9f69c6f6649e335e0f7ae8da58183c6/core/src/main/java/org/apache/sling/testing/mock/sling/RRMockResourceResolverWrapper.java#L113
>  returning {{null}} (which seems fine according to the contract which states 
> that {{null}}} might be returned and 
> https://github.com/apache/sling-org-apache-sling-jcr-resource/blob/89bc0bb344d6c7f109f6e43ef5e87bda7c04d286/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java#L320
>  unconditionally dereferencing it.
> I raised https://lists.apache.org/thread/tss0dlhqss5pzhqz89brlgryb3s44gh8 to 
> clarify whether JCR Resource Provider needs to be fixed as well.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to