Null value from resource resolver | Community
Skip to main content
Community Advisor
October 16, 2015
Solved

Null value from resource resolver

  • October 16, 2015
  • 4 replies
  • 6263 views

I am getting null resourcefrom the resource resolver. Here is the function I am calling, when I debugged I found path and resourseResolver is not null.

when I am at Resource resource = resourceResolver.getResource(path); I am getting resource as null. Attaching screenshot from eclipse

    private Asset getDamAssets(String path, ResourceResolver resourceResolver)
            throws RepositoryException {
        Asset asset = null;
        LOG.info("...getDamAssets at " + path);
        Resource resource = resourceResolver.getResource(path);

        if (resource != null) {
            // Convert resource to asset, returns null if not an asset
            asset = resource.adaptTo(Asset.class);
        }

        return asset;
    }

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by JustinEd3

Hi,

Usually that would indicate that either (a) the resource at that path does not exist or (b) it does exist and the user doesn't have read access to it.

Regards,

Justin

4 replies

October 16, 2015

Try resourceResolver.resolve(Path) it will work.

//This takes absolute path, you might be providing absolute path.

Lokesh_Shivalingaiah
Level 10
October 16, 2015

Hi,

path looks fine but I think that resource is not available at the given path and hence its throwing null. Please check if that resource exists at the give path. Also refer here [1]

[1]https://sling.apache.org/apidocs/sling5/org/apache/sling/api/resource/ResourceResolver.html#getResource(java.lang.String)

JustinEd3Adobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

Hi,

Usually that would indicate that either (a) the resource at that path does not exist or (b) it does exist and the user doesn't have read access to it.

Regards,

Justin

MshajiCommunity AdvisorAuthor
Community Advisor
October 16, 2015

resourceResolver.resolve(Path) works but following line now returns null

    asset = resource.adaptTo(Asset.class);

resource is not null, it is going into if loop but it seems that adaptTo Asset returns null now.