Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
Bug 153486 - Off-by-one bug in protected blocks
Off-by-one bug in protected blocks
Status: VERIFIED FIXED
Product: editor
Classification: Unclassified
Component: -- Other --
6.x
All All
: P2 (vote)
: 6.x
Assigned To: issues@editor
issues@editor
65fixes2-verified
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-11-19 20:47 UTC by _ gtzabari
Modified: 2009-02-19 20:45 UTC (History)
6 users (show)

See Also:
Issue Type: DEFECT
:


Attachments
full stacktrace (9.53 KB, text/plain)
2008-11-20 12:34 UTC, Petr Dvorak
Details

Note You need to log in before you can comment on or make changes to this bug.
Description _ gtzabari 2008-11-19 20:47:35 UTC
dev build 200811161401

Designer -> Pick some node (mine is a JTable) -> Customize Code -> "custom property"

Mine reads "mediaTable.setModel(abc);" where "mediaTable.setModel(" and ");" are colored as protected blocks. There
seems to be an off-by-one bug preventing me from deleting the "c" even though it isn't part of the protected block.

You can use CTRL+DEL to delete "c" but this is also the source of a second bug: I can use CTRL+DEL to delete protected
blocks. Even real ones!
Comment 1 Petr Dvorak 2008-11-20 12:27:59 UTC
Product Version: NetBeans IDE Dev (Build 200811180201)
Java: 1.6.0_10-rc; Java HotSpot(TM) Client VM 11.0-b13
System: Linux version 2.6.27-8-generic running on i386; UTF-8; en_US (nb)

Reproducible. Can be done in editor too!! Pressing ctrl+del deletes code in guarded block, eventually resulting in this
exception.

java.lang.AssertionError: Start offset must be before the end offset. startOffset = 28, endOffset = 27
	at org.netbeans.spi.editor.highlighting.support.OffsetsBag.addHighlightImpl(OffsetsBag.java:491)
	at org.netbeans.spi.editor.highlighting.support.OffsetsBag.addAllHighlightsImpl(OffsetsBag.java:724)
	at org.netbeans.spi.editor.highlighting.support.OffsetsBag.addAllHighlights(OffsetsBag.java:184)
	at
org.netbeans.modules.editor.lib2.highlighting.CompoundHighlightsContainer.updateCache(CompoundHighlightsContainer.java:302)
	at
org.netbeans.modules.editor.lib2.highlighting.CompoundHighlightsContainer.getHighlights(CompoundHighlightsContainer.java:170)
	at org.netbeans.editor.HighlightingDrawLayer.processOffset(HighlightingDrawLayer.java:618)
	at org.netbeans.editor.HighlightingDrawLayer.isActive(HighlightingDrawLayer.java:344)
	at org.netbeans.editor.DrawEngine.drawArea(DrawEngine.java:884)
	at org.netbeans.editor.DrawEngine.drawInternal(DrawEngine.java:1168)
	at org.netbeans.editor.DrawEngine.draw(DrawEngine.java:1074)
	at org.netbeans.editor.DrawEngineLineView.getModel2ViewRect(DrawEngineLineView.java:413)
Comment 2 Petr Dvorak 2008-11-20 12:34:04 UTC
Created attachment 73947 [details]
full stacktrace
Comment 3 _ gtzabari 2008-11-20 15:19:08 UTC
Please don't take away my workaround before you fix the off-by-one bug first :) Otherwise I'll *really* be stuck.
Comment 4 Petr Dvorak 2008-11-20 15:46:12 UTC
Well, the possibility to delete guarded code is a real problem, IMO.

I hope both problems (deleting guarded blocks and problem with edge conditions) will be fixed... As it is present in 6.5
FCS too, it is a good candidate for some patch, I guess... This problem is in mobility development too - reassigning
back to editor...

Ctrl+Delete and Ctrl+Backspace (delete next/previous word) shortcuts delete text in GB...
Comment 5 Jiri Prox 2008-11-20 16:09:18 UTC
Yes, it it reproducible in trunk build
strange is that is doesn't happen in parsing api build
Comment 6 Tomas Pavek 2008-11-20 18:59:28 UTC
The off-by-one seems to be issue 91288. Note there is a workaround for it (quite awkward) - when turning on the custom
code section, press space (will replace all the selected code), then move before the space by left cursor key and write
your code. This way you leave the space at the last problematic position and the text before it can be edited.
Comment 7 Miloslav Metelka 2008-11-25 10:30:41 UTC
I'll fix it - looks like runAtomic() is used instead of runAtomicAsUser().
Comment 8 Miloslav Metelka 2008-12-03 16:20:11 UTC
Fixed Ctrl+Del/Backspace deletes in guarded blocks - http://hg.netbeans.org/main/rev/1b21e44e55da
For off-by-one you can always type a single letter if the space between the blocks is empty. So you need to type the
last letter and move in front of it and type the identifier. I understand that it's ugly so I continue working on a fix.
Comment 9 _ gtzabari 2008-12-03 16:22:30 UTC
By the way, the main problem isn't typing into the dialog in the first place but rather changing what you typed after
the fact. Right now you can't change the code what-so-ever ;) Thanks for scheduling this for M1 though. I'll wait.
Comment 10 Quality Engineering 2008-12-05 06:04:46 UTC
Integrated into 'main-golden', will be available in build *200812050201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/1b21e44e55da
User: Miloslav Metelka <mmetelka@netbeans.org>
Log: #153486 - Off-by-one bug in protected blocks - Ctrl+Del/BackSpace deletes in guarded box fix.
Comment 11 Miloslav Metelka 2008-12-08 15:51:23 UTC
Partially fixed - it's now possible to type between two guarded blocks on a single line (GuardedDocument checks when
inserting inside line). However it's not possible to insert a code completion item since the CompletionImpl uses
GD.isPosGuarded(pos) which does not reflect whether insert/remove operation is attempted.
OTOH the editor.guards expects that GB starts at line's begining so I can't allow begin-line inserts as well.
Something has to be changed. Either GD.isPosGuarded() has to have variations or editor.guards must support allowed
begin-line inserts. Or we could have two GB types - one multi-line that would not allow begin-line inserts and in-line
type which would allow them.
Any ideas?

http://hg.netbeans.org/main/rev/bccd4b75f3b3
Comment 12 Miloslav Metelka 2008-12-09 15:11:56 UTC
After consulting both form team's requirements and editor.guards module's requirements I will implement the following fix:
1) If the guarded block starts at line's begining it's not possible to insert any text at line's begining except if it
contains '\n' as the last character.
2) If GB starts in the middle of a line it's possible to insert any character.
3) When removing a character a new-line before GB should not be removed (since then a GB that previously started at
line's begining could start in a middle of line) unless the char right before removal start is also '\n'.

This should reflect editor.guards module's behavior that it appends // GEN-BEGIN at the end of first guarded line and so
if we would allowed typing at the begining of such GB then a subsequent reopening of the file would cause the typed text
to become guarded.

If this would not suffice in the longterm we would have to have two GB types - one for editor.guards and another for the
special intra-line form folds.
Comment 13 Quality Engineering 2008-12-09 18:34:21 UTC
Integrated into 'main-golden', will be available in build *200812091520* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/bccd4b75f3b3
User: Miloslav Metelka <mmetelka@netbeans.org>
Log: #153486 - Off-by-one bug in protected blocks - partial fix.
Comment 14 Miloslav Metelka 2008-12-10 09:45:31 UTC
http://hg.netbeans.org/main/rev/8d7dcabd71b5
Comment 15 Quality Engineering 2008-12-11 06:00:03 UTC
Integrated into 'main-golden', will be available in build *200812110201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/8d7dcabd71b5
User: Miloslav Metelka <mmetelka@netbeans.org>
Log: #153486 - Off-by-one bug in protected blocks - final fix.
Comment 16 _ gtzabari 2009-01-06 21:44:24 UTC
I just wanted to point out that this P2 issue has not yet been back-ported to 6.5. Are there plans to do so?
Comment 17 pgebauer 2009-01-06 22:47:35 UTC
Based on the third bullet in "How to include issues into patch" (http://wiki.netbeans.org/NetBeansPatches), the issue must be fixed and verified by QE or by 
reporter in the trunk prior integration into the release65_fixes branch. So far the issue is just FIXED/RESOLVED. Sustaining is waiting for a verification in the 
trunk. If the issue isn't verified by January 13 2009 (the nomination cut-off date), it will be moved to the next patch.

Comment 18 Petr Dvorak 2009-01-08 11:46:43 UTC
Verified (off-by-one seems to be solved, guarded blocks cannot be deleted using Ctrl+Del/Backspace).

There is another bug with undoing, I will file it...
Comment 19 Petr Dvorak 2009-01-08 11:58:26 UTC
The mentioned undoing bug: #156469
Comment 20 pgebauer 2009-01-09 22:55:38 UTC
The fix has been ported into the release65_fixes repository.

http://hg.netbeans.org/release65_fixes/rev/d4c0f5667f86


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo