eppleton commented on code in PR #9691:
URL: https://github.com/apache/netbeans/pull/9691#discussion_r4246152046
##########
java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/BreakpointOutput.java:
##########
@@ -397,43 +414,43 @@ private String substitute (String printText,
JPDABreakpointEvent event) {
}
} catch (AbsentInformationException aiex) {}
}
- try {
- value = ((Variable)
theDebugger.getClass().getMethod("evaluate", String.class,
CallStackFrame.class).
- invoke(theDebugger, expression, csf)).getValue();
- } catch (InvocationTargetException itex) {
- if (itex.getTargetException() instanceof
InvalidExpressionException) {
- throw (InvalidExpressionException)
itex.getTargetException();
- }
- } catch (Exception ex) {
- Exceptions.printStackTrace(ex);
+ Variable refValue = theDebugger.evaluate(expression, csf);
+ if (refValue instanceof ObjectVariable obj) {
+ var sessionRef = new WeakReference<>(session);
+ io.printWithAction("#" + obj.getUniqueID(), () -> {
Review Comment:
`createVariable` wraps every `ObjectReference` and `null` in an
`AbstractObjectVariable`, so this branch now handles `String`s, `Class`
objects, arrays and `null` too. Before, they were printed with `getValue()`,
which shows `"Alice"`, `class Foo`, `#12(length=3)` and `null`. Now each prints
only `#<uniqueID>`, and `null` prints `#0`. A log point like `Name: {=name}`
therefore changes from `Name: "Alice"` to `Name: #1234`. Maybe print
`obj.getValue()` as the link text, or use the `#id` link only for plain objects?
##########
java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/BreakpointOutput.java:
##########
@@ -397,43 +414,43 @@ private String substitute (String printText,
JPDABreakpointEvent event) {
}
} catch (AbsentInformationException aiex) {}
}
- try {
- value = ((Variable)
theDebugger.getClass().getMethod("evaluate", String.class,
CallStackFrame.class).
- invoke(theDebugger, expression, csf)).getValue();
- } catch (InvocationTargetException itex) {
- if (itex.getTargetException() instanceof
InvalidExpressionException) {
- throw (InvalidExpressionException)
itex.getTargetException();
- }
- } catch (Exception ex) {
- Exceptions.printStackTrace(ex);
+ Variable refValue = theDebugger.evaluate(expression, csf);
+ if (refValue instanceof ObjectVariable obj) {
+ var sessionRef = new WeakReference<>(session);
+ io.printWithAction("#" + obj.getUniqueID(), () -> {
+ var s = sessionRef.get();
+ var ok = s != null &&
BreakpointOutputDetails.showObjectVariable(s, obj);
+ if (!ok) {
+ io.println("Cannot display details of " + obj,
null);
+ }
+ }, false);
+ } else {
+ String textualValue = refValue == null ? "null" :
refValue.getValue();
+ io.printWithAction(textualValue, null, false);
}
- //value = theDebugger.evaluate (expression, csf).getValue ();
- value = backslashEscapePattern.matcher (value).
- replaceAll ("\\\\\\\\");
- value = dollarEscapePattern.matcher (value).
- replaceAll ("\\\\\\$");
} catch (InvalidExpressionException e) {
// expression is invalid or cannot be evaluated
- String msg = e.getCause () != null ?
- e.getCause ().getMessage () : e.getMessage ();
- JPDADebuggerImpl dbg;
- synchronized (lock) {
- dbg = (JPDADebuggerImpl) debugger;
- }
- if (dbg != null) {
- dbg.getConsoleIO().println (
- "Cannot evaluate expression '" + expression + "' :
" + msg,
- null
- );
- }
+ String[] msg = new String[] {
+ e.getCause () != null ? e.getCause ().getMessage () :
e.getMessage ()
+ };
+ Breakpoint bp = (Breakpoint) event.getSource();
+ io.printWithAction("{=" + expression + "}", () -> {
Review Comment:
Two things on this link:
- javap shows `lambda$printExpressions$1(String[], DebuggerConsoleIO,
Breakpoint)`, so the `configure` link now captures `io` again.
`DebuggerConsoleIO` has a strong `JPDADebuggerImpl` field, which brings back
the retention that capturing only the `Breakpoint` had fixed.
- The evaluation error is no longer visible: the console shows only
`{=expr}`, and the message is printed when the link is clicked. Before, the
line read "Cannot evaluate expression 'x' : <reason>". Is it intended that the
reason is hidden until the user clicks?
--
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