Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » ContentAssist dilemma--keep getting BadLocationException on an insert
ContentAssist dilemma--keep getting BadLocationException on an insert [message #326528] Sat, 22 March 2008 17:05 Go to next message
Alex Le is currently offline Alex LeFriend
Messages: 649
Registered: July 2009
Senior Member
Hi,

I have content assist implemented on my editor.

Say, I start out a very fresh document and type in "ab" then Ctrl+Space
to activate the content assist. Then I choose a proposal from the list
and it has the string "foo(a,b)" to insert.

I keep encountering the below exception from the AbstractDocument class.
the 'pos + length' is always greater than what getLength() returned,
which is 2, the length of 'ab'. Any tips? Thanks.

public void replace(int pos, int length, String text, long
modificationStamp) throws BadLocationException {
if ((0 > pos) || (0 > length) || (pos + length > getLength()))
throw new BadLocationException();
Re: ContentAssist dilemma--keep getting BadLocationException on an insert [message #326530 is a reply to message #326528] Sat, 22 March 2008 17:31 Go to previous messageGo to next message
Alex Le is currently offline Alex LeFriend
Messages: 649
Registered: July 2009
Senior Member
AL wrote:
> Hi,
>
> I have content assist implemented on my editor.
>
> Say, I start out a very fresh document and type in "ab" then Ctrl+Space
> to activate the content assist. Then I choose a proposal from the list
> and it has the string "foo(a,b)" to insert.
>
> I keep encountering the below exception from the AbstractDocument class.
> the 'pos + length' is always greater than what getLength() returned,
> which is 2, the length of 'ab'. Any tips? Thanks.
>
> public void replace(int pos, int length, String text, long
> modificationStamp) throws BadLocationException {
> if ((0 > pos) || (0 > length) || (pos + length > getLength()))
> throw new BadLocationException();

Just to clarify that my insertion offset is zero, that is, attempting to
replace "ab" with "foo(a,b)".
Re: ContentAssist dilemma--keep getting BadLocationException on an insert [message #326559 is a reply to message #326528] Tue, 25 March 2008 10:52 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
AL wrote:
> Hi,
>
> I have content assist implemented on my editor.
>
> Say, I start out a very fresh document and type in "ab" then
> Ctrl+Space to activate the content assist. Then I choose a proposal
> from the list and it has the string "foo(a,b)" to insert.
Check that the offsets and lengths in your proposal is correct.

Dani
>
> I keep encountering the below exception from the AbstractDocument class.
> the 'pos + length' is always greater than what getLength() returned,
> which is 2, the length of 'ab'. Any tips? Thanks.
>
> public void replace(int pos, int length, String text, long
> modificationStamp) throws BadLocationException {
> if ((0 > pos) || (0 > length) || (pos + length > getLength()))
> throw new BadLocationException();
Re: ContentAssist dilemma--keep getting BadLocationException on an insert [message #326583 is a reply to message #326559] Tue, 25 March 2008 18:03 Go to previous messageGo to next message
Alex Le is currently offline Alex LeFriend
Messages: 649
Registered: July 2009
Senior Member
Daniel Megert wrote:
> AL wrote:
>> Hi,
>>
>> I have content assist implemented on my editor.
>>
>> Say, I start out a very fresh document and type in "ab" then
>> Ctrl+Space to activate the content assist. Then I choose a proposal
>> from the list and it has the string "foo(a,b)" to insert.

> Check that the offsets and lengths in your proposal is correct.

Double-check with debugging sessions, still something is wrong. My
replacement offset is zero, that is, positioning at the 'a' in "ab",
which is to be replaced. My replacement length is 8, which is the
length of "foo(a,b)".

And keep encountering the below exception.

> Dani
>>
>> I keep encountering the below exception from the AbstractDocument class.
>> the 'pos + length' is always greater than what getLength() returned,
>> which is 2, the length of 'ab'. Any tips? Thanks.
>>
>> public void replace(int pos, int length, String text, long
>> modificationStamp) throws BadLocationException {
>> if ((0 > pos) || (0 > length) || (pos + length > getLength()))
>> throw new BadLocationException();
Re: ContentAssist dilemma--keep getting BadLocationException on an insert [message #326635 is a reply to message #326583] Thu, 27 March 2008 01:25 Go to previous message
Alex Le is currently offline Alex LeFriend
Messages: 649
Registered: July 2009
Senior Member
AL wrote:
>> Check that the offsets and lengths in your proposal is correct.
>
> Double-check with debugging sessions, still something is wrong. My
> replacement offset is zero, that is, positioning at the 'a' in "ab",
> which is to be replaced. My replacement length is 8, which is the
> length of "foo(a,b)".
>
> And keep encountering the below exception.
>

Dud! the replacement length to use is 2 NOT 8; it's the length of the
text to be replaced by the new text. I had done ContentAssist
before...Somehow misunderstood the parameter description!
:-)

>>> I keep encountering the below exception from the AbstractDocument class.
>>> the 'pos + length' is always greater than what getLength() returned,
>>> which is 2, the length of 'ab'. Any tips? Thanks.
>>>
>>> public void replace(int pos, int length, String text, long
>>> modificationStamp) throws BadLocationException {
>>> if ((0 > pos) || (0 > length) || (pos + length > getLength()))
>>> throw new BadLocationException();
Previous Topic:where to get the draw2d source
Next Topic:implementing my own contentmergeviewer
Goto Forum:
  


Current Time: Sat Nov 09 00:59:21 GMT 2024

Powered by FUDForum. Page generated in 0.03340 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top