Oops Null Pointer

Java programming related

Creating UML Sequence Diagrams from Debug / Stack traces

I found a good tool to create sequence / class interaction diagrams from Java stack traces or debug stacks using a free Eclipse plugin called AmaterasUML. Install it in Eclipse and you can open a “Sequence diagram from stacktrace” view, paste in a stacktrace and it will generate a nice looking sequence diagram.

With a bit of text manipulation you can modify a debug trace (from right-click “Copy Stack” on the debug window) to look like a stack trace and generate the UML from a debug breakpoint. The steps are:

  • Add “at ” to the start of every line
  • Replace method args with the class name.java:line number
  • Clean up $2$1 type class suffixes

E.g.

EventRegistryImpl.fireEvent(Event) line: 47
BaseFolderNavigator$2.handleEvent(Event) line: 79
CoverageNavigatorViewGXT(BaseObservable).fireEvent(Event) line: 27
BaseNavigatorViewGXT$2$1.execute() line: 149

becomes

at EventRegistryImpl.fireEvent(EventRegistryImpl.java:47)
at BaseFolderNavigator.handleEvent(BaseFolderNavigator.java:79)
at CoverageNavigatorViewGXT(BaseObservable).fireEvent(CoverageNavigatorViewGXT.java:27)
at BaseNavigatorViewGXT.execute(BaseNavigatorViewGXT.java:149)

Below is a gawk command (via UnxUtils) to convert a stack file (x.txt) to a stacktrace

gawk "{str = $0; sub(/^\t/, \"^\", str);match(str, /(.*)\./, arr); sub(/^/, \"^at \", str);sub(/\(.*\./,\".\",str);sub(/\([^\)]*\)/, \"(\", str);sub(/ line: /, arr[1]\".java:\", str);sub(/$/, \")\", str);sub(/\t\)$/, \"\)\", str);print str}" x.txt
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: