Yes @Nicolas Peltier<mailto:npelt...@adobe.com>, this makes sense and is in alignment with JCR Observation where a JCR path containing [and] is considered invalid and a RepositoryException is thrown. Let me look into the code and figure out the right place to put a check. I’ll keep this thread posted!
-Rafiya From: Nicolas Peltier <npelt...@adobe.com> Date: Friday, 13 March 2020 at 9:54 PM To: Rafiya Sirin <si...@adobe.com>, "users@sling.apache.org" <users@sling.apache.org> Cc: Sandeep Kambi Nanjundeshwara <s...@adobe.com> Subject: Re: [Sling JCR resource] ResourceChangeListeners fail to register Hey Rafiya, Bubbling up to where those excluded paths are generated, I get to ResourceProviderTracker.updateProviderContext crawling through its handler keyset. What seems awkward to me is that this path, with [ and ] chars is considered valid. I would not have that path registered at all in the first place. From: Rafiya Sirin <si...@adobe.com> Date: Thursday 12 March 2020 at 22:09 To: "users@sling.apache.org" <users@sling.apache.org>, Nicolas Peltier <npelt...@adobe.com> Cc: Sandeep Kambi Nanjundeshwara <s...@adobe.com> Subject: [Sling JCR resource] ResourceChangeListeners fail to register Hi All, I was trying to register a simple ResourceChangeListener and it failed with the attached stack trace. A small snippet from it : [org.apache.sling.api.resource.observation.ResourceChangeListener, org.apache.sling.event.jobs.consumer.JobConsumer]] ServiceEvent REGISTERED 05.03.2020 23:39:00.728 *ERROR* [FelixDispatchQueue] org.apache.sling.resourceresolver FrameworkEvent ERROR (java.lang.NullPointerException) java.lang.NullPointerException: null at org.apache.jackrabbit.oak.commons.PathUtils.unifyInExcludes(PathUtils.java:501) [org.apache.jackrabbit.oak-commons:1.8.17] at org.apache.jackrabbit.oak.jcr.observation.ObservationManagerImpl.addEventListener(ObservationManagerImpl.java:240) [org.apache.jackrabbit.oak-jcr:1.8.17] at org.apache.sling.jcr.resource.internal.JcrListenerBaseConfig.register(JcrListenerBaseConfig.java:136) [org.apache.sling.jcr.resource:3.0.16.1] On a deeper analysis, I found that it was due to getOakPath() [0] returning a null for one of the paths. The path that returned null was /libs/[/globalnav-page, /localnav-page]/xyzTargetIds.json.POST.servlet. This is a servlet in our codebase which is registered in following manner : SLING_SERVLET_RESOURCE_TYPES + "=[" + RT_GLOBALNAV_PAGE + "," +RT_LOCALNAV_PAGE + "]", which caused the same path to be constructed and an oak path was expected to be present for it. Since it wasn’t present, a null was stored in the excludes Set which ultimately caused the NPE and listener failed to register. When I changed the initialization of this servlet to follow the practices, property = { SLING_SERVLET_RESOURCE_TYPES + "=" + RT_GLOBALNAV_PAGE, SLING_SERVLET_RESOURCE_TYPES + "=" + RT_LOCALNAV_PAGE, issue is fixed. I am working on raising a PR [OAK-8948] in oak-jcr to *warn* for paths which return a null for getOakPath() for awareness and also a check for null in PathUtils.java just in case. Meanwhile, I think we should also have a check in Sling on the way context’s exclude paths are constructed? Or maybe block it even earlier by not allowing to go on and register in case of a bad path. Let me know your thoughts on this. Thanks, Rafiya Sirin [0] - https://github.com/apache/jackrabbit-oak/blob/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java#L394