Community
Participate
Working Groups
The NullPointerException actually ocurrs in StyledTextPrinter.run. StyledText.getRtf returns null when there is no text. I'll update the javadoc for StyledText.getRtf to point out that null is returned when the widget has no text.
As suggested below, return the RTF for an empty file. getText is API, getRtf is not. Internally StyledText returns null in a couple of places (I think). I consider getRtf internal, too. I don't feel strongly about null vs. "" - I wouldn't mind changing it. I'm just not convinced that changing it is the right thing to do. Having thought about this, returning an empty string doesn't sound right because we claim to return RTF. When there is no text we should probably return RTF for no text, i.e., just the header. That seems better to me than returning null or "". Knut I will check for null if you like, but Steve says you really should return empty string for consistency with other SWT functions. For example, back in Smalltalk, getSelection on a List with nothing selected used to return nil. Every single app used to get burned by that, so it got changed to an empty collection. Today in SWT, getSelection on List returns an empty array if there is no selection. There are a lot of methods like that: getItems, getColumns, getChildren. Even if you look at getText, you return an empty string if there's no text. So getRtf should probably also return an empty string if there's no text. Do you agree? Car
When there is no text we now return an RTF string with just the header and no body.