mbien commented on code in PR #9207:
URL: https://github.com/apache/netbeans/pull/9207#discussion_r2838986071


##########
ide/parsing.lucene/src/org/netbeans/modules/parsing/lucene/RecordOwnerLockFactory.java:
##########
@@ -230,4 +177,25 @@ private static void stackTrace(
             sb.append('\t').append(se).append('\n');    //NOI18N
         }
     }
+
+    record DirectoryLockPair(Directory directory, String lock) {
+
+        private static final Set<Thread> RECURSION_PROTECTION = 
ConcurrentHashMap.newKeySet();
+
+        @Override
+        public String toString() {
+            // The directory also outputs the lock in toString(), we need to
+            // protect unlimited recursion
+            if(RECURSION_PROTECTION.contains(Thread.currentThread())) {
+                return "<<RECURSION>>";
+            }
+            try {
+                RECURSION_PROTECTION.add(Thread.currentThread());
+                return "DirectoryLockPair{" + directory + ", " + lock + "}";
+            } finally {
+                RECURSION_PROTECTION.remove(Thread.currentThread());
+            }

Review Comment:
   I tried to find a simpler solution and added a commit to a copy of this 
branch:
   https://github.com/mbien/netbeans/commits/update-lucene3/
   
https://github.com/mbien/netbeans/commit/4367c9de143155053fe8a041a029cd4c4dae5366
   
   I think not calling `directory.toString()` from `factory.toString()` could 
be a compromise which allows simpler code, since it should be still easy to get 
to the directory during debugging if so desired.
   
   it has another change related to Exception creation. It allows to disable 
the stack traces to make it a little JFR friendlier. Since JFR has an event for 
created exceptions, carrying the unfortunate name of 
[`JavaExceptionThrow`](https://sap.github.io/jfrevents/21.html?search=JavaExceptionThrow).
 Makes it easier to distinguish real exceptions from ones used as debug utility.
   
   feel free to squash into your code if you like it.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to