Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 225760

Summary: NullPointerException in AbstractEditPolicy#toString() when called w/o host set
Product: [Tools] GEF Reporter: Jens Von Pilgrim <developer>
Component: GEF-Legacy GEF (MVC)Assignee: Anthony Hunter <ahunter.eclipse>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: ahunter.eclipse
Version: 3.2.1   
Target Milestone: 3.5.0 (Galileo) M5   
Hardware: All   
OS: All   
Whiteboard:

Description Jens Von Pilgrim CLA 2008-04-04 11:22:24 EDT
The toString() method in AbstractEditPolicy causes a NullPointerException when it is called without a host set:

public String toString() {
	String c = getClass().getName();
	c = c.substring(c.lastIndexOf('.') + 1);
	return getHost().toString() + "." + c;//$NON-NLS-1$         <------- exception
}

IMHO toString() methods, primarily used for logging and debugging, should be more robust, i.e. they should never throw an exception, especially if it is so easy to avoid.

Suggestion:

public String toString() {
	String c = getClass().getName();
	c = c.substring(c.lastIndexOf('.') + 1);
        if (getHost()!=null)
	   return getHost().toString() + "." + c;//$NON-NLS-1$
        else
           return c + " (no host set yet)";
}
Comment 1 Anthony Hunter CLA 2009-01-23 17:27:23 EST
Good catch and you are right.

Fixed in HEAD as you have suggested.