| Summary: | org.eclipse.jface.text.TextPresentation(0) throws Assertion error | ||
|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Jacek Pospychala <jacek.pospychala> |
| Component: | Text | Assignee: | 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: | |||
Why should it allow 0? What's a sensible use case for that? 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. > 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.
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. Jacek, besides the fact that ArrayList allows it, do you have another argument/reason why you need to pass 0 at all? nope (In reply to comment #6) > nope ;-) |
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