I'm trying check if a container is present or not in groovy script but it's throwing null pointer exception I'm handling that as below,
getPage(parent).recurse {
page ->
def content = page.node
def property = content.get('sling:resourceType')
if (property == "project/components/product-page") {
count++;
println page.path;
def footercontainer = getNode(page.path+"/jcr:content/root/container_1845659030");
def refcontainer = getNode(page.path+refNode);
if(getNode(page.path+footercontainer) != null){
if(footercontainer.hasProperty(propName1)){
(footercontainer).getProperty(propName1).remove();
}
}
Views
Replies
Total Likes
able to get pages with template but for some pages that container is not present, so there it's throwing nullpointer exception which I'm not able to handle through groovy.
in which line were you getting null pointer exception
Hi @KKeerthi
The reason you are getting a null pointer exception is because you are passing the footercontainer variable to the getNode method, which is expecting a string path. Instead, you should pass the string path directly to the getNode method.
getPage(parent).recurse { page ->
def content = page.node
def property = content.get('sling:resourceType')
if (property == "project/components/product-page") {
count++
println page.path
def footercontainer = getNode(page.path+"/jcr:content/root/container_1845659030")
def refcontainer = getNode(page.path+refNode)
if (getNode(page.path+"/jcr:content/root/container_1845659030") != null) {
if (footercontainer.hasProperty(propName1)) {
footercontainer.getProperty(propName1).remove()
}
}
}
}
we pass the string path directly to the getNode method instead of passing the footercontainer variable. This should resolve the null pointer exception.
Fixed this.
Views
Replies
Total Likes
@KKeerthi Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies