Multifield Model Null pointer exception | Community
Skip to main content
NaziyaP
Level 2
February 7, 2022
Solved

Multifield Model Null pointer exception

  • February 7, 2022
  • 2 replies
  • 1826 views

Dear All,

 

We have implemented Multifield component along with Model using Resource.

But we are getting null pointer exception when we are trying to get use Resource object.

 

Core Class:

import org.apache.sling.models.annotations.Model;

import org.apache.sling.api.resource.Resource;

@Model(
adaptables = {Resource.class},
adapters = {MultifieldModel.class},
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL
)
public class MultifieldModelImpl implements MultifieldModel {

@586265
Resource componentResource;

public List<Map<String, String>> getDetailsWithMap() {
List<Map<String, String>> detailsMap=new ArrayList<>();
try {
Resource detailfield=componentResource.getChild("nodename/path");

}

}

}

 

Multifield Interface :

public interface MultifieldModel {
String getFieldTitle();
List<Map<String,String>> getDetailsWithMap();
}

 

in component we using this by data sly:
data-sly-use.field="pathtoclass.MultifieldModel"

 

when we render pages using this Model componentResource(

reosurce object) is giving as null.

 

This same code is workign fine in Dev env in both author- publisher and in production authors but only giving error in Production publishers.

 

Request you please suggest things we can modify or check in pub to make it work.

 

Thanks in advance

 

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 Vijayalakshmi_S

@naziyap 

Suggesting the below given the same code is working fine in DEV and PROD author. 

  • Cross check if the multifield resource is available/accessible from PROD publish instance.
    • If you have access to CRXDE, check the same or if its accidentally removed 
    • Can try replicating the page containing multifield component and check (PROD publish app server and in admin login, if possible)

2 replies

Sanjay_Bangar
Community Advisor
Community Advisor
February 7, 2022

Hi @naziyap ,

    Make it public specfier and then try it.

@inject
Public Resource componentResource

Kr,

Sanjay

Vijayalakshmi_S
Vijayalakshmi_SAccepted solution
Level 10
February 7, 2022

@naziyap 

Suggesting the below given the same code is working fine in DEV and PROD author. 

  • Cross check if the multifield resource is available/accessible from PROD publish instance.
    • If you have access to CRXDE, check the same or if its accidentally removed 
    • Can try replicating the page containing multifield component and check (PROD publish app server and in admin login, if possible)
NaziyaP
NaziyaPAuthor
Level 2
February 14, 2022

Hello Vijayalakshmi_S,

 

Thank you for your reply.

 

We have checked that resource is present in crx but when we try to hit that page even with pub ip port it still gives us same error.

I have tried creating new page with multifield components and published the same all changes are reflecting fine but still only that component is not rendering and keep on giving null pointer exception.

 

Vijayalakshmi_S
Level 10
February 14, 2022

@naziyap 

Can you confirm if you are accessing the Publish application server with admin login ?

If yes and there is no access related issue, compare the problematic resource with working resource to narrow down the cause.