This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 226236 - A way of telling the debugger what value to be used.
Summary: A way of telling the debugger what value to be used.
Status: REOPENED
Alias: None
Product: debugger
Classification: Unclassified
Component: Code (show other bugs)
Version: 7.3
Hardware: PC All
: P3 normal (vote)
Assignee: Martin Entlicher
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-17 19:19 UTC by Chiana
Modified: 2013-02-19 11:32 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chiana 2013-02-17 19:19:14 UTC
[ JDK VERSION : 1.7.0_13 ]

This is a suggestion of a way to tell the debugger that it is not safe to use
the .toString() method call.

1) Implement a method with the signature;
  private String <name>() {}
2) Make a note to the debugger that it can recognize.
" // DEBUGGER: value"
or something similar.
The result would be

class Veird {
    Object data=null;

    public Veird() {
       data=null;
    }

  public String toString() {
     return ""+data.toString();  // NPE is possibly to be thrown here
  }

  // DEBUGGER: value
  private String debugValue() {
     if (data==null) return "Null value";
     return "Data="+data.toString();
  }
}
Comment 1 Martin Entlicher 2013-02-18 13:39:18 UTC
IMHO this is not worth the effort. When toString() method throws exceptions, it's a problem of the toString() implementation in the first place IMHO.

If there are classes, where an alternate representation is necessary, Variable Formatters can be used:
Tools -> Options -> Java -> Java Debugger -> Variable Formatters
Comment 2 Chiana 2013-02-19 10:03:35 UTC
Yes, I'm aware of that, the problem with that is that it is a global setting, not a setting per class or project, this can cause confusion if you forget to remove the entry when going to the next project, this way (or by a similar means) the setting will follow the class and will be used automatically.
Also can be said that you can throw heavy objects from toString without beeing a flawed design.
Comment 3 Chiana 2013-02-19 11:32:41 UTC
This is just to make another point; This does not just apply to the toString method, consider the following;

When it comes to List and similar structures the debugger calls the .size() method, that is not always desirable, if you for example have a scheme that do some fancy working (f.ex. cleaning up arrays, loading data et.c.) the debugger will actually affect the result, but with this type of tagging you can always assure that the correct result is produced and the debugger do not affect the outcome, look at this;

class WhatEver {
  Object [] info;
  boolean loaded=false;

...

  public int size() {
   if (info == null && !loaded) {
     loadData();
     loaded=true;
   }
   return info==null ? 0 : info.length;
  }
}

In this case the debugger will affect the outcome by making a call to "loadData()" and that is probable not what you want.
I know you can use variable formatters to get around this but that still requires you to make a method that the debugger can use safely, example
  // DEBUGGER: size
  public int size2() {
    return info==null ? 0 : info.length;
  }
so why not make something that makes it easier to use.