JDK-4857236 : RFE: Include watched objects stack traces
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2003-05-01
  • Updated: 2006-11-15
  • Resolved: 2006-11-15
Related Reports
Relates :  
Description
Name: rmT116609			Date: 05/01/2003


A DESCRIPTION OF THE REQUEST :
Add the ability to mark objects where the value ofString.valueOf() would included in any stack trace.  In my example below I used "trace". Variables that aren't declared at the point of the stack trace would just be ingored.

JUSTIFICATION :
It would make debugging much easier and make it much easier to write programs that are easy to debug.

 

EXPECTED VERSUS ACTUAL BEHAVIOR :
java.lang.NullPointerException:
	at Test.main(Test.java:7) index=0, sum=3, obj=null
java.lang.NullPointerException:
	at Test.main(Engine.java:124)

Or doesn't compile if the "trace" keyword is included.

---------- BEGIN SOURCE ----------
public class Test {
  Object obj;
  public void main(String[] args) trace obj {
    trace int sum = 0;
    for(trace int index = 0; index < args.length; index++) {
      sum += Integer.parseInt(args[index]);
      sum += obj.hashCode();//Will cause NullPointerException
    }
  }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Catch Throwable and re-throw it with more info. The method would also have to be declared to throw Throwable.
(Review ID: 182848) 
======================================================================

Comments
EVALUATION I don't see this as an essential language feature. Adding a new keyword is always difficult, and this one would require VM support (since NullPointerException isn't thrown by compiler-generated code but would nevertheless need various values passed to its constructor for 'trace' to be useful).
15-11-2006