rishabhdaim commented on code in PR #243:
URL: 
https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/243#discussion_r4664072670


##########
src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java:
##########
@@ -562,6 +593,13 @@ private String loadVanityPath(
         }
 
         for (final String pVanityPath : pVanityPaths) {
+
+            // collect vanity path values that seem to be broken
+            final String diagnostics = 
diagnoseDubiousVanityPath(resource.getPath(), pVanityPath);
+            if (!diagnostics.isEmpty() && dubiousVanityPaths.size() <= 
MAX_REPORT_DUBIOUS_VANITY_PATHS) {

Review Comment:
   ๐ŸŸก **P3** ยท ๐ŸŽฏ Correctness
   
   **๐Ÿ” Issue:** `<= MAX_REPORT_DUBIOUS_VANITY_PATHS` admits a 51st example 
despite the 50-entry limit, and the new test does not exercise saturation.
   
   **๐Ÿ› ๏ธ Fix:** Use `<` and add boundary cases around 50 that also assert later 
vanity values are still mapped.



##########
src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java:
##########
@@ -544,7 +574,8 @@ private String loadVanityPath(
             final Map<String, List<MapEntry>> entryMap,
             final Map<String, List<String>> targetPaths,
             boolean addToCache,
-            boolean updateCounter) {
+            boolean updateCounter,
+            final List<String> dubiousVanityPaths) {

Review Comment:
   ๐ŸŸก **P3** ยท ๐Ÿ—๏ธ Design
   
   **๐Ÿ” Issue:** All three non-startup callers now allocate diagnostic lists and 
format messages that they immediately discard.
   
   **๐Ÿ› ๏ธ Fix:** Keep collection startup-only, following `AliasHandler`'s 
nullable collector pattern, and check collector presence/capacity before 
formatting without skipping mapping processing.



##########
src/test/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathMapEntriesTest.java:
##########
@@ -335,6 +336,36 @@ private void prepareMapEntriesForSingleVanityPath(String 
node, String vanityPath
                 });
     }
 
+    @Test
+    public void test_simple_dubious_vanity_path() {
+        // a dubious vanity path
+        String vanityPath = "empty//path//segment";
+
+        String containerName = "foo";
+        String childName = "child";
+        String oneMore = "one-more";
+        prepareMapEntriesForVanityPath(false, false, containerName, childName, 
oneMore, vanityPath);
+
+        try (TestLogger logger = TestLogger.create(VanityPathHandler.class)
+                .contains("dubious vanity paths")
+                .start()) {
+            initializeVanityPaths();
+            List<String> logs = logger.stopAndGetLogs();
+            // 1 because both resources share the same broken vanity path
+            assertEquals(1, logs.size());
+            // dubious vanity path results in resource name in root with "-" 
stripped??
+            assertTrue(logs.get(0).contains("onemore"));

Review Comment:
   ๐ŸŸก **P3** ยท ๐ŸŽฏ Correctness
   
   **๐Ÿ” Issue:** Both dubious values are relative, so this test never reaches 
the empty-segment reason and only checks that the warning contains `onemore`.
   
   **๐Ÿ› ๏ธ Fix:** Add assertions for each new reason and resource/value 
attribution, plus a clean absolute value that emits no diagnostic warning.



##########
src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java:
##########
@@ -522,6 +544,14 @@ private Map<String, List<String>> 
loadVanityPaths(ResourceResolver resolver) {
             }
         }
 
+        // warn about dubious vanity paths
+
+        if (dubiousVanityPaths.size() >= MAX_REPORT_DUBIOUS_VANITY_PATHS) {
+            log.warn("There are {} dubious vanity paths; excerpt: {}", 
dubiousVanityPaths.size(), dubiousVanityPaths);

Review Comment:
   ๐ŸŸก **P3** ยท โš™๏ธ Production operations
   
   **๐Ÿ” Issue:** Once the sample fills, 52 dubious values and thousands both log 
`There are 51 dubious vanity paths`; `excerpt` does not qualify that count.
   
   **๐Ÿ› ๏ธ Fix:** Say `at least` for a saturated sample or maintain a separate 
total, and assert the logged count with input exceeding the sample capacity.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to