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.
When i edit a swing panel or frame and so on, if i select my code for an event handler, and i insert a try-catch block with the "Surround with try-catch" feature, the entire method become read only and is not more editable. Example: private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) { try { // bla bla bla // now i cannot edit this anymore } } catch (Exception ex) { // bla bla bla } }
Please provide build # and steps to reproduce. I cannot reproduce it.
I cannot reproduce it in recent dev. build. Please provide more information how to reproduce it. Which build are you using?
the build is 20051122 and previous. Is not always possible to reproduce, however try this: 1) Create a new JPanel. 2) Using Swing editor, add a JButton to the panel. 3) Select the button, and select properties->events 4) Add an actionPerformed event to the button. 5) Go to the source editor and insert some code into the handler that raise an exception private void jButtonActionPerformed(java.awt.event.ActionEvent evt) { // add this } Note that the declaration of the handler and the last bracket are read only (blu background) 6) Select all the code you've inserted (try selecting all the code except for the declaration of the ancler and the last bracket) 7) Select the Surround with try-catch option. Often (not always), all the code that is suorrounded become read only (bacground blu) and the only way to make it editable is to copy the whole code, delete the event, recreate it, and paste the copied code.
Milane, can you test it?
*** Issue 69185 has been marked as a duplicate of this issue. ***
*** Issue 69107 has been marked as a duplicate of this issue. ***
I'm not able to reproduce (I will try more). mazzuco, do you insert some white spaces around in the event handler? Do you use code folding? Have you done some kind of refactoring in the file before (or even renaming the class itself)? Have you inserted some methods/fields? Please be specific as much as you can. Thanks.
usually i leave a blank line after the declaration and before the last bracket, because sometimes if i select all the code between the two read-only lines, i obtain a message like "cannot surround selected block with try-catch". I use code folding, setted this: inner class and import I don't remember if i've done some refractoring, but it's possible, i use the refactor often. The class has both method written by myself and auto-generated event handler. Unfortunally is hard to reproduce it.. i've tried to create a new panel and handler.. and it works, but, sometimes, in a my older project (started with earlyer 4.2 netbeans), it happens. The only thing i can do, if you want, is to send you, the next time i'll obtain this issue, the source of the class and the .form file.
Created attachment 27339 [details] example of code after the try-catch
Created attachment 27340 [details] the same code BEFORE making try-catch
I've attached an example of the issue that i've recreated. Look at the private void fileChooserActionPerformed(java.awt.event.ActionEvent evt) - Before trying-catching the group, the method declaration is non-editable only until the last character: ")" and not to the end of the line. - I've select all the code inside, i've made the surround option, and now, the fileChooserActionPerformed is all read-only
Sorry, mistake: before surrounding the line: private void fileChooserActionPerformed(java.awt.event.ActionEvent evt) { is not editable until two space after the left { bracket, and not to the end of line: (i'll attach another small jpg to show how i see it)
Created attachment 27343 [details] strange behaviour
It seems to be really reproducible for me with attached example sources. Open Filechooser.java (from trycatchbefore.zip) in editor and select body of the fileChooserActionPerformed method and invoke Surround with try-catch action - you should get the whole method read-only. When you do undo it's undone and never happen for me, but if you save and close the file you have read-only method forever.
I'm not sure if we will be able to fix this for 5.0. The problem occurs only in case that first statement in a blcok is surrounded by try-catch.
Fixed in trunk. (using hot fix) Checking in org/netbeans/modules/javacore/jmiimpl/javamodel/MetadataElement.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/MetadataElement.java,v <-- MetadataElement.java new revision: 1.69; previous revision: 1.68 done Checking in org/netbeans/modules/javacore/jmiimpl/javamodel/StatementBlockImpl.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/StatementBlockImpl.java,v <-- StatementBlockImpl.java new revision: 1.11; previous revision: 1.10 done
I've found bug in the fix. See attached screenshot, it happened when adding System.out.println(s); in the middle of the method body and executing hint create local variable.
Created attachment 28144 [details] screenshot
Not reproducible always.
I'm able to reproduce it. -- Good catch. It is little bit different scenario. The difference is, that in first case, first statement was replaced by new one (try-catch). In your new case, there is inserted new element, the original first element is now second.
Hopefully correct fix. Milane, can you test it once more, please? Thanks. Checking in src/org/netbeans/modules/javacore/jmiimpl/javamodel/MetadataElement.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/MetadataElement.java,v <-- MetadataElement.java new revision: 1.70; previous revision: 1.69 done
Verified, I'm not able to reproduce the problem in trunk build 200601031900.
Please, don't forget to get code review and commit the fix into release50 branch. Thanks.
The fix is safe.
Merged from trunk. Checking in src/org/netbeans/modules/javacore/jmiimpl/javamodel/MetadataElement.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/MetadataElement.java,v <-- MetadataElement.java new revision: 1.67.2.1; previous revision: 1.67 done Checking in src/org/netbeans/modules/javacore/jmiimpl/javamodel/StatementBlockImpl.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/StatementBlockImpl.java,v <-- StatementBlockImpl.java new revision: 1.10.6.1; previous revision: 1.10 done
Verified in release50-rc1.
Reorganization of java component