Page is throwing NullPointerException upon activation in AEM Sites

Description

Issue
When a page is activated in AEM, the activation fails with the following exception

javax.servlet.ServletException: java.lang.NullPointerException
at com.day.cq.wcm.core.impl.reference.ActivationReferenceSearchServlet.doGet(ActivationReferenceSearchServlet.java:175)
at org.apache.sling.api.servlets.SlingSafeMethodsServlet.mayService(SlingSafeMethodsServlet.java:269)

Environment
AEM 6.x
Cause
This was happening because one of the images referenced by the page had an issue with it’s properties. The image causing issues was missing the cq:lastReplicated property while it had the cq:lastReplicatedBy and cq:lastReplicationAction properties.

Specified Message
javax.servlet.ServletException: java.lang.NullPointerException
at com.day.cq.wcm.core.impl.reference.ActivationReferenceSearchServlet.doGet
at org.apache.sling.api.servlets.SlingSafeMethodsServlet.mayService

Resolution

  1. Identify all the images which have this conflict
SELECT * FROM dam:Asset AS parent INNER JOIN nt:base AS child ON ISCHILDNODE(child,parent) WHERE ISDESCENDANTNODE(parent, '/content/dam/journey/') AND child.cq:lastReplicated IS NULL AND child.cq:lastReplicatedBy IS NOT NULL
  1. Once the assets are identified, check if these assets were actually replicated or not.

  2. If yes, you can add the property cq:lastReplicated with the type Date and copy the date from the publish server.

  3. In either case, you can remove the cq:lastReplicatedBy and cq:lastReplicatedAction properties and Activate the image once again.

On this page