Bug 5622 - StyledText - print causes NPE when invoked on empty widget
Summary: StyledText - print causes NPE when invoked on empty widget
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows NT
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Knut Radloff CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-11-07 11:27 EST by Knut Radloff CLA
Modified: 2001-11-08 10:09 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Knut Radloff CLA 2001-11-07 11:27:17 EST
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.
Comment 1 Lynne Kues CLA 2001-11-07 15:20:34 EST
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
Comment 2 Knut Radloff CLA 2001-11-08 10:09:37 EST
When there is no text we now return an RTF string with just the header and no 
body.