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 250995 - org.netbeans.editor.GuardedException: Attempt to remove from guarded block at position 1
Summary: org.netbeans.editor.GuardedException: Attempt to remove from guarded block at...
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 8.0
Hardware: All All
: P3 normal (vote)
Assignee: Ralph Ruijs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-07 17:59 UTC by cezariusz
Modified: 2015-04-07 06:33 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter: 204535


Attachments
stacktrace (2.89 KB, text/plain)
2015-03-07 17:59 UTC, cezariusz
Details
proposed patch (954 bytes, patch)
2015-03-27 16:58 UTC, Svata Dedic
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description cezariusz 2015-03-07 17:59:17 UTC
This issue was reported manually by cezariusz.
It already has 3 duplicates 


Build: NetBeans IDE 8.0.2 (Build 201411181905)
VM: Java HotSpot(TM) 64-Bit Server VM, 25.25-b02, Java(TM) SE Runtime Environment, 1.8.0_25-b18
OS: Windows 7

User Comments:
GUEST: I was doing a refactor (rename) of a class.

vikas_netbeans: i am jusy dragging and droping the jlabel when this error occurs...

cezariusz: Refactor to safely delete an automatically generated main function in a dialog.




Stacktrace: 
org.netbeans.editor.GuardedException: Attempt to remove from guarded block at position 1
Comment 1 cezariusz 2015-03-07 17:59:19 UTC
Created attachment 152467 [details]
stacktrace
Comment 2 cezariusz 2015-03-07 18:02:45 UTC
I have created a dialog using New -> Swing GUI Forms -> JDialog Form. I was created with a main function, which I didn't want. So I clicked on it in the Members navigator, right click -> Refactor -> Safely Delete. The exception has been reported and the function wasn't removed.
Comment 3 Ralph Ruijs 2015-03-25 13:48:35 UTC
SafeDelete uses TreeMaker.removeClassMember(), reassigning to java.source.
Comment 4 Svata Dedic 2015-03-27 12:59:26 UTC
The culprit is the CasualDiff / WorkingCopy; this time, because it attached a comment to a Java element (main method) across a guarded block boundary.

There's another subtle issue:

Suppose you add some Label to the dialog - then try to delete the method. The refactoring module insists that the part of text is readonly. I believe there's a
"+- 1" error in RefactoringElementsBag.java:222 - the condition should read like

                        if (section.contains(elementStart, true) ||
                            (section.contains(elementEnd, true) && 
                                section.getStartPosition().getOffset() != elementEnd.getOffset())) {
                            return true;
                        }

The element's end is actually a position right after the element text, so it may share offset with guarded block begin, as the character on that offset will not be actually deleted.
Comment 5 Svata Dedic 2015-03-27 16:58:51 UTC
Created attachment 152888 [details]
proposed patch

Part of the bug is being fixed as jet-main#e30db8faa778. 
Proposed changes to refactoring API attached.
Comment 6 Quality Engineering 2015-04-03 03:06:46 UTC
Integrated into 'main-silver', will be available in build *201504030001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/e30db8faa778
User: Svata Dedic <sdedic@netbeans.org>
Log: #250995: member pos estimator respects Guarded boundaries when accummulating surrounding whitespaces and comments
Comment 7 Ralph Ruijs 2015-04-07 06:33:32 UTC
Thanks you for the patch, integrated as a24a65e0e399