eppleton commented on code in PR #9757:
URL: https://github.com/apache/netbeans/pull/9757#discussion_r4510890483


##########
java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/actions/AddLogpointAction.java:
##########
@@ -80,6 +81,18 @@ public void actionPerformed(ActionEvent ev) {
         lb.setSuspend(JPDABreakpoint.SUSPEND_NONE);
         lb.setPrintText(Bundle.MSG_LogpointAt("{className}", "{methodName}", 
"{lineNumber}", "{locals}"));
 
+        addOrReplaceBreakpoint(lb);
+    }
+
+    private static void addOrReplaceBreakpoint(LineBreakpoint lb) {
+        Comparator<Comparable<Object>> comp = Comparator.naturalOrder();
+        for (Breakpoint existing : 
DebuggerManager.getDebuggerManager().getBreakpoints()) {
+            if (lb instanceof Comparable c1 && existing instanceof Comparable 
c2) {
+                if (comp.compare(c1, c2) == 0) {
+                    
DebuggerManager.getDebuggerManager().removeBreakpoint(existing);

Review Comment:
   This removes the existing breakpoint rather than converting it, so whatever 
the user configured on it is gone: condition, hit count, thread/class filters, 
custom print text, enabled state, group. Also, `LineBreakpointImpl.compareTo` 
only compares URL and line number and ignores the lambda index, so a breakpoint 
on a lambda on the same line is removed as well, although it stops at a 
different location.
   
   I checked it locally by calling `addOrReplaceBreakpoint` the same way 
`actionPerformed` does:
   - a line breakpoint with condition `x > 5` and a hit-count filter, then a 
logpoint on the same line: only the new logpoint is left, and the condition and 
hit count are gone;
   - a breakpoint with lambda index `0`, then a logpoint on the same line: the 
lambda breakpoint is removed;
   - two logpoints on the same line: one entry, as intended.
   
   A smaller change that would avoid both: replace only an existing *logpoint*, 
i.e. a breakpoint on the same URL, line and lambda index with `SUSPEND_NONE`. 
For a regular breakpoint on that line, either leave it and do nothing, or 
switch it to non-suspending and keep its settings. Comparing `getURL()` and 
`getLineNumber()` directly would also be easier to read than the raw 
`Comparable`.



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