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 56206 - NbDocument API unmarkGuarded(,,) & JavaEditor.SimpleSection.removeSection() adds a new line during removal of guard
Summary: NbDocument API unmarkGuarded(,,) & JavaEditor.SimpleSection.removeSection() a...
Status: RESOLVED WORKSFORME
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 4.x
Hardware: All All
: P3 blocker (vote)
Assignee: issues@java
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-10 22:01 UTC by Ayub Khan
Modified: 2007-09-26 09:14 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ayub Khan 2005-03-10 22:01:48 UTC
Both NbDocument API unmarkGuarded(,,) & JavaEditor.SimpleSection.removeSection
() inserts a newline during removal of guarded, when the guarded section 
includes the last line in a document.
For Eg:-
Text Document (non-java document)

int totalLineCount = getDocument().getDefaultRootElement().getElementCount();

//totalLineCount is 25

//just create a guarded region including the entire document
NbDocument.markGuarded(document, 0, document.length);

//do no edit the document

//now remove the guarded section
NbDocument.unmarkGuarded(document, 0, document.length);

totalLineCount = getDocument().getDefaultRootElement().getElementCount();

//totalLineCount is 26

Java Document

int totalLineCount = getDocument().getDefaultRootElement().getElementCount();

//totalLineCount is 25

//just create a guarded region including the entire document
JavaEditor javaEditor = getCookie();
PositionBounds bounds=javaEditor.createBounds(
0, document.length, false); 
JavaEditor.SimpleSection simpleSection = javaEditor.createSimpleSection
(bounds,regionName);

//do no edit the document

//now remove the guarded section
simpleSection.removeSection();

totalLineCount = getDocument().getDefaultRootElement().getElementCount();

//totalLineCount is 26
Comment 1 Petr Nejedly 2005-03-11 15:25:41 UTC
Trying to write a test.
Comment 2 Petr Nejedly 2005-03-11 16:06:08 UTC
I wrote a test that proves NbDocument behaves correctly, so the problem is most
probably in GuardedDocument in editor library. Feel free to reuse my test using
your Document impl...

openide/test/unit/src/org/openide/text/NbDocumentTest.java,v1.1
Comment 3 Miloslav Metelka 2005-03-21 16:58:05 UTC
I'm going to attempt to fix it into 4.1.
Comment 4 Miloslav Metelka 2005-04-01 14:31:47 UTC
We will reuse your test under our org.netbeans.modules.editor.openide package in
unit tests where we already reuse other openide/editor tests.
Comment 5 Roman Strobl 2005-04-06 14:40:59 UTC
Changing TM to 4.2 and adding 41_HR_FIX kw according to:
http://www.netbeans.org/community/releases/41/high-resistance.html
Comment 6 Miloslav Metelka 2005-04-06 16:29:07 UTC
I have inherited Petr's test. I have extracted new DefaultStyledDocument() into
createStyledDocument() protected method in the original test.

Checking in test/unit/src/org/openide/text/NbDocumentTest.java;
/cvs/openide/test/unit/src/org/openide/text/NbDocumentTest.java,v  <-- 
NbDocumentTest.java
new revision: 1.2; previous revision: 1.1
Checking in
test/unit/src/org/netbeans/modules/editor/openide/InheritedNbDocumentTest.java;
/cvs/editor/test/unit/src/org/netbeans/modules/editor/openide/InheritedNbDocumentTest.java,v
 <--  InheritedNbDocumentTest.java
initial revision: 1.1


The inherited test works fine on NbEditorDocument implementation. I have tested
the part until the "Java Document" of the problematic code and for me it works
properly (does not modify the document - I've added
-J-Dnetbeans.debug.editor.document=true to watch for possible changes but there
was none extra change).

However I have inspected the methods used in the rest of the problematic code -
namely JavaEditor.createSimpleSection() and there is some code dealing with
adding the new-lines around line 822 in JavaEditor:

Util.ExceptionRunnable run = new Util.ExceptionRunnable() {
    public void run() throws Exception {
        int where = pos.getOffset();
        doc.insertString(where, "\n \n", null); // NOI18N
        sect[0] = new SimpleSection(name,
            createBounds(where + 1, where + 3, false));
        sections.put(sect[0].getName(), sect[0]);
        sect[0].markGuarded(doc);
    }
};

Passing to java module for further evaluation.
Comment 7 Miloslav Metelka 2005-04-06 16:54:50 UTC
Oops, that was createSimpleSection(PositionRef, String) but not
createSimpleSection(PositionBounds, String).

Anyway, ayubskhan, could you please include the build number of the IDE where
you've tested this? Thanks.
Comment 8 Tomas Hurka 2005-04-06 17:10:21 UTC
I do not see any reason why this should not work for JavaEditor.SimpleSection, if 
NBDocumnet.unmarkGuarded(,,) works OK. Please provide NetBeans build number and platform. 
Thanks.
Comment 9 Ayub Khan 2005-04-06 18:40:52 UTC
I have tested also tested this issue against NB4.1 Qbuild from 01 April 2005.
Comment 10 Martin Matula 2005-04-06 21:29:24 UTC
What version of JDK were you running with? Why is this a P2 bug (seems like an
edge-case which is not exposed by any of the current NetBeans functionality)?
At least the first part of the issue does not seem to be reproducible with our
tests. We will try the second part (Java document), anyway, it is likely it
won't be reproducible too, since if for you even the first part was broken that
would imply the second part being broken since JavaEditor calls
NbDocument.markGuarded() and unmarkGuarded() internally.
Could you provide a test that reproduces this problem? Is this really a
showstopper bug for NetBeans 4.1 release? To me it seems like a P3 at least.
Comment 11 Miloslav Metelka 2005-04-07 08:40:00 UTC
Please also consider running your code causing the problems with the document
modifications tracing capability turned on (prefixing with -J when using with NB
runner):
-J-Dnetbeans.debug.editor.document=true
And in addition
-J-Dnetbeans.debug.editor.document.stack=true
will show the stacktraces of who called the modification so it should become
visible which code invokes the modification.
Comment 12 Ayub Khan 2005-04-07 08:59:30 UTC
Lowering Priority to P3. This is not a stopper for Nb4.1.

I will try debbuging this issue, by setting the following flags.

-J-Dnetbeans.debug.editor.document=true
And in addition
-J-Dnetbeans.debug.editor.document.stack=true
Comment 13 Martin Matula 2005-04-07 09:42:16 UTC
Thanks a lot!
Comment 14 Martin Matula 2005-08-29 23:02:32 UTC
Any news?
Comment 15 Milan Kubec 2005-11-01 12:35:22 UTC
ayubskhan, do you have any news about this issue?
Comment 16 Ayub Khan 2005-11-01 16:55:26 UTC
I am not using JavaEditor.SimpleSection for now. I have switched to
EditorSupport.SimpleSection.

So, IMO we can close this bug or lower priority.
Comment 17 Miloslav Metelka 2005-11-03 11:33:37 UTC
Closing the issue as worksforme.