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

Bug 327091

Summary: org.eclipse.jface.text.TextPresentation(0) throws Assertion error
Product: [Eclipse Project] Platform Reporter: Jacek Pospychala <jacek.pospychala>
Component: TextAssignee: Platform-Text-Inbox <platform-text-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: minor    
Priority: P3 CC: daniel_megert
Version: 3.6.1   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Jacek Pospychala CLA 2010-10-06 07:21:34 EDT
hi,
TextPresentation(int sizeHint) asserts sizeHint >0 and then uses it to create ArrayList, which accepts not only >0, but also 0 as initial size.. Why TextPresentation doesn't allow 0 in sizeHint?

TextPresentation(int sizeHint) {
Assert.isTrue(sizeHint > 0);
fRanges= new ArrayList(sizeHint);
}


ArrayList(int initialCapacity) {
public ArrayList(int initialCapacity) {
	super();
        if (initialCapacity < 0) throw errrorr
Comment 1 Dani Megert CLA 2010-10-06 10:52:50 EDT
Why should it allow 0? What's a sensible use case for that?
Comment 2 Jacek Pospychala CLA 2010-10-06 11:53:40 EDT
We've hit this in bug 326776. In that bug we're just passing some regions list to TextPresentation, so we call:

new TextPresentation(damage, regions.size()) 

Sometimes regions.size() is 0 in which case above fails, so now we learned that we need one more extra condition to avoid 0.
But I'm not fully understanding why TextPresentation fails on 0.
Comment 3 Dani Megert CLA 2010-10-06 11:59:59 EDT
> we need one more extra condition to avoid 0.
> But I'm not fully understanding why TextPresentation fails on 0.
Because in general it makes no sense to create useless objects. I assume your code can easily function well without creating an empty TextPresentation, right? And if your code adds ranges later, then it would make sense to make the initial size larger than the initial amount of ranges.
Comment 4 Jacek Pospychala CLA 2010-10-07 04:13:01 EDT
sure, we can create TextPresentation with positive sizeHint argument, that's not problem :-)
The problem is that, when most Java APIs allow creating useless objects but some small parts of APIs suddenly don't allow it with no real reason it makes using them more difficult.
Comment 5 Dani Megert CLA 2010-10-07 04:20:07 EDT
Jacek, besides the fact that ArrayList allows it, do you have another argument/reason why you need to pass 0 at all?
Comment 6 Jacek Pospychala CLA 2010-10-07 04:35:38 EDT
nope
Comment 7 Dani Megert CLA 2010-10-07 05:06:25 EDT
(In reply to comment #6)
> nope
;-)