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 112764 - GuardedException:Attempt to insert into guarded block at position
Summary: GuardedException:Attempt to insert into guarded block at position
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 6.x
Hardware: All Windows XP
: P3 blocker (vote)
Assignee: Max Sauer
URL: http://statistics.netbeans.org/except...
Keywords:
: 111922 114472 118681 118703 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-08-14 16:16 UTC by Fabiola Rios
Modified: 2008-09-03 15:15 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter: 2743


Attachments
stacktrace (1.37 KB, text/plain)
2007-10-22 10:45 UTC, Lukas Hasik
Details
stacktrace (1.37 KB, text/plain)
2007-10-28 23:05 UTC, zrjian
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Fabiola Rios 2007-08-14 16:16:20 UTC
build 20070813

Just try to add some Throws clause to the simpleCancellableTask in source editor and the follo exception appears:

org.netbeans.editor.GuardedException: Attempt to insert into guarded block at position 7,321.
	at org.netbeans.editor.GuardedDocument.preInsertCheck(GuardedDocument.java:156)
	at org.netbeans.editor.BaseDocument.insertString(BaseDocument.java:554)
	at org.netbeans.api.java.source.ModificationResult.commit(ModificationResult.java:94)
Caused: java.io.IOException
	at org.netbeans.api.java.source.ModificationResult.commit(ModificationResult.java:105)
	at org.netbeans.api.java.source.ModificationResult.commit(ModificationResult.java:67)
	at org.netbeans.modules.java.hints.errors.UncaughtException$AddThrowsClauseHintImpl.implement(UncaughtException.java:222)
	at org.netbeans.modules.editor.hints.HintsUI$1.run(HintsUI.java:543)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:539)
[catch] at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:964)
Comment 1 David Kaspar 2007-08-14 17:01:51 UTC
This issue is caused by java/editor module. Reassigning.
Comment 2 Jan Lahoda 2007-08-15 09:03:24 UTC
Should be OK now:
Checking in UncaughtException.java;
/cvs/java/hints/src/org/netbeans/modules/java/hints/errors/UncaughtException.java,v  <--  UncaughtException.java
new revision: 1.4; previous revision: 1.3
done
Checking in Utilities.java;
/cvs/java/hints/src/org/netbeans/modules/java/hints/errors/Utilities.java,v  <--  Utilities.java
new revision: 1.5; previous revision: 1.4
done
Checking in CreateElement.java;
/cvs/java/hints/src/org/netbeans/modules/java/hints/errors/CreateElement.java,v  <--  CreateElement.java
new revision: 1.12; previous revision: 1.11
done
Comment 3 Fabiola Rios 2007-08-21 13:02:53 UTC
build 20070821

The problem  is still there, the follow exception appears whole the time. ={

org.netbeans.editor.GuardedException: Attempt to remove from guarded block at position 25,030.
	at org.netbeans.editor.GuardedDocument.preRemoveCheck(GuardedDocument.java:192)
	at org.netbeans.editor.BaseDocument.remove(BaseDocument.java:706)
	at org.netbeans.api.java.source.ModificationResult.commit(ModificationResult.java:100)
Caused: java.io.IOException
	at org.netbeans.api.java.source.ModificationResult.commit(ModificationResult.java:105)
	at org.netbeans.api.java.source.ModificationResult.commit(ModificationResult.java:67)
	at org.netbeans.modules.java.hints.errors.Utilities.commitAndComputeChangeInfo(Utilities.java:216)
	at org.netbeans.modules.java.hints.errors.CreateMethodFix.implement(CreateMethodFix.java:177)
	at org.netbeans.modules.editor.hints.HintsUI$1.run(HintsUI.java:545)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:539)
[catch] at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:964)
Comment 4 Jan Lahoda 2007-08-21 13:06:21 UTC
What exactly are you doing?

BTW: why is it P2 now?
Comment 5 Jan Becicka 2007-08-21 13:59:39 UTC
Dupe of issue 90424?
Comment 6 Fabiola Rios 2007-08-21 14:23:42 UTC

We agree to increase the priority,  because you can't add code in a mobile application without get the exception ={.
and we can not test another parts of the product because of that.
Comment 7 Jan Lahoda 2007-08-21 15:19:31 UTC
I took another look at the second trace and it is different from the original one - I guess it probably should be
covered by issue #90424 (it depends on exact use-case, it might also be a separate bug). The original problem of this
issue (attempt to modify method header which is inside a guarded block) should be fixed by the above commit (the "Add
throws clause" and "Add parameter" hints should not appear at all).

Anyway, I tried to reproduce the second exception a bit, and I did not succeed. Could you please describe exact steps to
reproduce?  Thanks.
Comment 8 Lukas Hasik 2007-10-12 13:23:07 UTC
it is still reproducible. Duplicate issue 118681 has 5 duplicates in exception reporter database therefore I'm
increasing priority to P2 again.

Steps:
1, create new Visula MIDlet in Mobility project. The Visual Midlet opens with Flow view opened
2, in Navigator right click "MIDP Visual design > Resources" and choose "New/Add > Simple Cancellable Task"
3, right click the new task "Go to Source"
4, in source code write a line that provides you hint into one of following sections "write task-execution user code
here", " write pre-init user code here", "write post-init user code here" - > for example newMethod();
5, use hint "Create Method newMethod in" -> exception
Comment 9 Lukas Hasik 2007-10-12 13:23:25 UTC
*** Issue 118681 has been marked as a duplicate of this issue. ***
Comment 10 Jan Lahoda 2007-10-15 16:08:56 UTC
Ok, I did some changes which should ensure that the hints (or generate code dialog) fail gracefully in presence of
guarded blocks. Not optimal, but acceptable for the time being, IMO.

Checking in java/editor/src/org/netbeans/modules/java/editor/codegen/GeneratorUtils.java;
/cvs/java/editor/src/org/netbeans/modules/java/editor/codegen/GeneratorUtils.java,v  <--  GeneratorUtils.java
new revision: 1.24; previous revision: 1.23
done
Checking in java/editor/src/org/netbeans/modules/java/editor/codegen/Bundle.properties;
/cvs/java/editor/src/org/netbeans/modules/java/editor/codegen/Bundle.properties,v  <--  Bundle.properties
new revision: 1.12; previous revision: 1.11
done
Checking in java/editor/src/org/netbeans/modules/java/editor/codegen/DelegateMethodGenerator.java;
/cvs/java/editor/src/org/netbeans/modules/java/editor/codegen/DelegateMethodGenerator.java,v  <-- 
DelegateMethodGenerator.java
new revision: 1.15; previous revision: 1.14
done
Checking in java/editor/src/org/netbeans/modules/java/editor/codegen/EqualsHashCodeGenerator.java;
/cvs/java/editor/src/org/netbeans/modules/java/editor/codegen/EqualsHashCodeGenerator.java,v  <-- 
EqualsHashCodeGenerator.java
new revision: 1.23; previous revision: 1.22
done
Checking in java/editor/src/org/netbeans/modules/java/editor/codegen/GetterSetterGenerator.java;
/cvs/java/editor/src/org/netbeans/modules/java/editor/codegen/GetterSetterGenerator.java,v  <--  GetterSetterGenerator.java
new revision: 1.13; previous revision: 1.12
done
Checking in java/editor/src/org/netbeans/modules/java/editor/codegen/ImplementOverrideMethodGenerator.java;
/cvs/java/editor/src/org/netbeans/modules/java/editor/codegen/ImplementOverrideMethodGenerator.java,v  <-- 
ImplementOverrideMethodGenerator.java
new revision: 1.10; previous revision: 1.9
done
Checking in java/editor/src/org/netbeans/modules/java/editor/codegen/ConstructorGenerator.java;
/cvs/java/editor/src/org/netbeans/modules/java/editor/codegen/ConstructorGenerator.java,v  <--  ConstructorGenerator.java
new revision: 1.14; previous revision: 1.13
done
Checking in java/source/src/org/netbeans/api/java/source/ModificationResult.java;
/cvs/java/source/src/org/netbeans/api/java/source/ModificationResult.java,v  <--  ModificationResult.java
new revision: 1.25; previous revision: 1.24
done
Checking in editor/hints/src/org/netbeans/modules/editor/hints/Bundle.properties;
/cvs/editor/hints/src/org/netbeans/modules/editor/hints/Bundle.properties,v  <--  Bundle.properties
new revision: 1.9; previous revision: 1.8
done
Checking in editor/hints/src/org/netbeans/modules/editor/hints/HintsUI.java;
/cvs/editor/hints/src/org/netbeans/modules/editor/hints/HintsUI.java,v  <--  HintsUI.java
new revision: 1.40; previous revision: 1.39
done
Comment 11 Jan Lahoda 2007-10-15 16:11:40 UTC
*** Issue 118703 has been marked as a duplicate of this issue. ***
Comment 12 Jan Lahoda 2007-10-15 16:52:29 UTC
*** Issue 111922 has been marked as a duplicate of this issue. ***
Comment 13 Jan Becicka 2007-10-17 11:42:55 UTC
Should be already fixed. Please verify.

*** This issue has been marked as a duplicate of 90424 ***
Comment 14 Pavel Flaska 2007-10-17 13:28:34 UTC
More problems were reported in this issue, partially covered by #90424, but definitely not a duplicate IMO.
Comment 15 Lukas Hasik 2007-10-17 20:03:37 UTC
reproduced in 20071016 b2 build -> definitely not duplicate of 90424

org.netbeans.editor.GuardedException: Attempt to remove from guarded block at position 6,590.
	at org.netbeans.editor.GuardedDocument.preRemoveCheck(GuardedDocument.java:214)
	at org.netbeans.editor.BaseDocument.remove(BaseDocument.java:748)
	at org.netbeans.api.java.source.ModificationResult.commit(ModificationResult.java:152)
Caused: java.io.IOException
	at org.netbeans.api.java.source.ModificationResult.commit(ModificationResult.java:160)
	at org.netbeans.api.java.source.ModificationResult.commit(ModificationResult.java:108)
	at org.netbeans.modules.java.hints.errors.MagicSurroundWithTryCatchFix.implement(MagicSurroundWithTryCatchFix.java:129)
	at org.netbeans.modules.editor.hints.HintsUI$1.run(HintsUI.java:574)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:561)
[catch] at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:986)

the source code after us of the hint:
    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem ">                                   
    /**
     * Returns an initiliazed instance of stringItem component.
     * @return the initialized component instance
     */
    public StringItem getStringItem() {
        if (stringItem == null) {                                 
            try {
                // write pre-init user code here
            stringItem = new StringItem("Hello", "Hello, World!");                                   
            // write post-init user code here
            throw new Exception();
        }                         
        return stringItem;
    }
    //</editor-fold>  

you can see missing catch + exception appears. 
Comment 16 Lukas Hasik 2007-10-17 20:17:05 UTC
I forgot to provide the beginning of the exception

WARNING [org.netbeans.modules.editor.hints.AnnotationHolder]: Incorrect highlight computed, please reopen issue #112566
and attach the following output: [6766-6757]=>[6766-6757]
SEVERE
Comment 17 Lukas Hasik 2007-10-17 20:18:48 UTC
*** Issue 114472 has been marked as a duplicate of this issue. ***
Comment 18 Jan Lahoda 2007-10-17 21:13:38 UTC
As I wrote above, the hints should fail gracefully in presence of guarded blocks - a reasonable error message should be
presented to the user. Also the commit should be atomic per file, so this shouldn't be breaking any code. Sorry, but it
is not going to be generally (ie. for all hints) better for NB6.0.

I went through almost all the fixes and made sure the error handling will get chance to present the proper error.


All of this was on trunk.
Comment 19 Lukas Hasik 2007-10-20 10:33:55 UTC
this issue has more than 15 duplicates now. Do expect more.
Comment 20 Lukas Hasik 2007-10-22 10:45:19 UTC
Build: NetBeans IDE 6.0 Beta 2 (Build 200710212201)
VM: Java HotSpot(TM) Client VM, 1.5.0_12-b04
OS: Windows XP, 5.1, x86

User Comments: 
1, add "throw new Exception();" code to a pre/post code in a Form
2, go to source code ad use the "surround try-catch" hint -> exception
Comment 21 Lukas Hasik 2007-10-22 10:45:27 UTC
Created attachment 51392 [details]
stacktrace
Comment 22 Lukas Hasik 2007-10-22 10:51:44 UTC
this issue is reproducible with java se project as well. The user scenario is little bit different then in mobility. In
mobility you are writing code out of guarded block because the guarded block are split into small pieces. In Java
SE(Form) the code that should be surrounded is _inside_ the guarded block.

1, Java SE
<guarded block start/>

  throw new Exception();

<guarded block end/>

2, Mobility

<guarded block start>
... a code ...
<guarded block end>

   throw new Exception();
<guarded block start>
... a code ...
<guarded block end>
Comment 23 zrjian 2007-10-28 23:05:09 UTC
Build: NetBeans IDE Dev (Build 200710280000)
VM: Java HotSpot(TM) Client VM, 1.6.0_03-b05
OS: Windows XP, 5.1, x86

User Comments: 
Comment 24 zrjian 2007-10-28 23:05:12 UTC
Created attachment 51856 [details]
stacktrace
Comment 25 Lukas Hasik 2007-10-31 12:27:00 UTC
there isn't any exception anymore. There is a red message in status bar instead.

BUT we cannot use the hints in mobility between the guarded blocks at all now -> issue 120599
Comment 26 Jana Maleckova 2008-01-02 14:10:35 UTC
the exception is throwing again :(
I tried to use hint which should implement all abstract methods => exception occurred
Code which arises this hint is placed in guarded block - off course
(e.g. jTable1.setModel(new AbstractTableModel(); )

Product Version: NetBeans IDE 6.0.1 (Build 200801020000)
Java: 1.6.0_04; Java HotSpot(TM) Client VM 10.0-b19
System: Windows XP version 5.1 running on x86; Cp1252; en_GB (nb)
Comment 27 Jan Becicka 2008-05-15 13:18:46 UTC
Max volunteered :)
Comment 28 Max Sauer 2008-09-03 14:10:36 UTC
Works ok with anonymous AbstractTableModel:

jTable1.setModel(new AbstractTableModel() {});
Comment 29 Max Sauer 2008-09-03 14:11:38 UTC
I'll fix the last case..
Comment 30 Max Sauer 2008-09-03 15:15:53 UTC
Fixed. Jano, please verify, thanks.
---
http://hg.netbeans.org/main/rev/3adc3b5f7c0e