Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Common cause for NullPionterException or Null value in Junit test case for sling model in aem


Community Advisor

Dear Members,

I came across with above problem while debugging some junit test cases for sling model.


"Let say your sling model is adaptables to sling Resource and in your test class you are trying to get the instance of your respective Object by adapting request of aemContext. In this case you will end up with NullPointerException."


Details are below:



Please provide your feedback, if any to make it more helpful.



Umesh Thakur

1 Reply


Community Advisor

You can add, addModelsForPackage, as this is another common null returned from adapt.