Expand my Community achievements bar.

SOLVED

Getting a nullpointer exception for PageContext on AEM 6.1

Avatar

Former Community Member

Hello,

I am getting the following exception when I try to drop a component onto the page.

My template is all in sightly but the component is a jsp component.Component worked well with 5.6.1 the templates we had there.

Thats caused by the following lines(bold and underline) of the code - 

<%

%><%@include file="/apps/banners/global.jsp"%><%
%><%@page session="false" import="com.svu.sites.cq5.components.search.SiteSearchResults"%><%
%><%
    SiteSearchResults searchResults = new SiteSearchResults(pageContext);
    pageContext.setAttribute("searchResults", searchResults);
%>

Exception : - 

Caused by: org.apache.sling.api.SlingException: An exception occurred processing JSP page /apps/brands/components/content/sitesearchresults/sitesearchresults.jsp at line 9
    at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspExceptionInternal(JspServletWrapper.java:683)
    at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:608)
    at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:533)
    at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:449)
    at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:284)
    at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:102)
    at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:536)
    at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:361)
    ... 123 common frames omitted
Caused by: java.lang.NullPointerException: null
    at com.svu.sites.cq5.components.search.SiteSearchResults.search(SiteSearchResults.java:85)
    at com.svu.sites.cq5.components.search.SiteSearchResults.init(SiteSearchResults.java:51)
    at com.crownpartners.cq.components.AbstractComponent.<init>(AbstractComponent.java:152)
    at com.svu.sites.cq5.components.search.SiteSearchResults.<init>(SiteSearchResults.java:38)
    at org.apache.jsp.apps.brands.components.content.sitesearchresults.sitesearchresults_jsp._jspService(sitesearchresults_jsp.java:183)
    at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:502)
    ... 128 common frames omitted

1 Accepted Solution

Avatar

Correct answer by
Level 10

Not all calls work in Sightly that work in JSP. For this use case - try using JSP and see if your component works. THat will tell us for sure if there is an issue with using this API with Sightly. 

View solution in original post

4 Replies

Avatar

Level 10

Hi Sonali,

Based on the log you have put in, it seems to be a Null pointer exception thrown in SiteSearchResults.java at line #85. Please check what is happening there.

 

Regards,

Lokesh

Avatar

Level 10
SiteSearchResults is a custom Java class correct?     

Avatar

Former Community Member

It is a custom class which extends AbstractComponent and gets all the site configuration details - 

Line 85 :   SiteConfigurationService scs = WebUtils.getSiteConfigurationService(this);
        String rootPath = scs.getSiteRootPath();

Not sure why it wont work since it works for all other sites on the same environment.

Although the difference here is we are using sightly templates and the component being dropped in is jsp.

And,rest of our java classes are extending from SiteConfigurationUse.

I just want to make it work with the existing code though with AbstractComponent.

Avatar

Correct answer by
Level 10

Not all calls work in Sightly that work in JSP. For this use case - try using JSP and see if your component works. THat will tell us for sure if there is an issue with using this API with Sightly.