This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 17144 - Problem with unchecked exceptions in Line.Set.getCurrent
Summary: Problem with unchecked exceptions in Line.Set.getCurrent
Alias: None
Product: platform
Classification: Unclassified
Component: Text (show other bugs)
Version: 3.x
Hardware: PC Linux
: P4 blocker (vote)
Assignee: Peter Zavadsky
Depends on:
Blocks: 16696
  Show dependency tree
Reported: 2001-10-30 21:07 UTC by Jesse Glick
Modified: 2008-12-22 22:59 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2001-10-30 21:07:32 UTC
[dev oct 30] Consider the following stack trace (how it happened is

java.lang.IllegalArgumentException: Line index=-1 must be >= 0
	at org.openide.text.NbDocument.findLineOffset(
	at org.openide.text.DocumentLine$Set.getCurrent(

Line.Set.getCurrent is declared to throw IndexOutOfBoundsException if
passed an illegal line number. In fact apisupport is here catching
that exception and ignoring it safely. But NbDocument.findLineOffset
which actually does the work is not declared to throw anything. Nor is
javax.swing.text.Element.getElement. In fact the editor module
implementation of it throws a different unchecked exception, which is
not at all documented. I guess this is an API bug although I am not
sure what should be done about it. Probably NbDocument.findLineOffset
should be changed to explicitly say IOOBE may be thrown (this is
technically incompatible but oh well), the editor module changed to
throw it, and the Editor API edited to recommend that editors throw
this exception from Element where appropriate.
Comment 1 Peter Zavadsky 2001-10-31 09:59:38 UTC
Well, its complicated a bit. 

1) javax.swing.text.Element doesn't declare which exception it throws,
just emphasizes the argument should be >=0. The
AbsractDocument.BranchElement implementation throws IOOBE exception in
that case, but it doesn't describe it in javadoc.
So I guess one part the BaseDocument.LineRootElement should also throw
IOOBE instead of IAE.

2) NbDocument.findLineOffset doesn't declare the exception IOOBE to be
thrown but it would be the good way I think. I looked at the code and
seen there could even NPE to be thrown, there is not counted with the
situation null line element is returned when too big line number is
This has to be handled the way IOOBE is thrown.

In sum I would do it this way:
1) BaseDocument.LineRootElement to throw IOOBE instead of IAE
2) NbDocument.findLineOffset handle the possible null element and
throw IOOBE in that case.
3) Probably the most problematic, is it possible to add to javadoc of
NbDocument.findLineOffset it can throw IOOBE or leave it that way.

Your opinion is needed first.

Comment 2 Jesse Glick 2001-10-31 13:10:13 UTC
IMHO: do 1. and 2. and add that to the Javadoc for 3. It should
probably be mentioned in apichanges.xml in <compatibility> as
incompatible but with the explanation: you should explicitly catch
IOOBE from this method; formerly it was not documented to throw this
but in fact did throw other undocumented (and less pleasant)
exceptions, so code using findLineOffset directly is probably no worse
off than it was, and code using it indirectly via Line.Set etc. will
already be fine.
Comment 3 Miloslav Metelka 2001-10-31 13:49:12 UTC
Now throwing IOOBE instead of IAE in BaseDocument to be compatible
with Swing.
Comment 4 Peter Zavadsky 2001-10-31 14:06:05 UTC
Fixed in [main-trunk].

openide/../openide/text/ [1.46].

Jesse, so the above is done. But I don't want to put the state its
incompatible change.

From NbDocument.findLineOffset could be thrown unchecked:
IOOBE if 'standard' swing doc was used.
IAE if our editor's doc was used, what is fixed now,
NPE if the index was bigger than amount of lines.
(Of course also other ugly thing could happen but we are interested
just for the above cases).

For all above cases should be alway IOOBE thrown, what is documented
now also.

I guess this is the similar case like we solved a time ago with
declaring some type of unchecked excpetion which could be thrown what
wasn't declared before but could happen. We decided not to put a state
an incompatible change was made.
What do you think?
(Added Yarda to cc to get his opinion as well if needed).
Comment 5 Jesse Glick 2001-11-01 11:43:33 UTC
OK, I still think it should be listed in apichanges with the above
explanation, need not be marked incompatible.
Comment 6 Peter Zavadsky 2001-11-02 08:41:50 UTC
Done: openide/api/doc/changed/apichanges.xml [1.33]
Comment 7 Quality Engineering 2003-07-01 16:01:52 UTC
Resolved for 3.4.x or earlier, no new info since then -> verified
Comment 8 Quality Engineering 2003-07-01 16:36:42 UTC
Resolved for 3.4.x or earlier, no new info since then -> closing.