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 69208 - Surrounding with try-catch option often make a method read only
Summary: Surrounding with try-catch option often make a method read only
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 5.x
Hardware: All Windows XP
: P2 blocker (vote)
Assignee: Pavel Flaska
URL:
Keywords:
: 69107 69185 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-11-23 17:26 UTC by mazzuco
Modified: 2007-09-26 09:14 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
example of code after the try-catch (1.76 KB, application/octet-stream)
2005-11-28 14:39 UTC, mazzuco
Details
the same code BEFORE making try-catch (1.73 KB, application/octet-stream)
2005-11-28 14:41 UTC, mazzuco
Details
strange behaviour (123.08 KB, image/jpeg)
2005-11-28 14:52 UTC, mazzuco
Details
screenshot (6.74 KB, image/png)
2006-01-03 13:39 UTC, Milan Kubec
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mazzuco 2005-11-23 17:26:18 UTC
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
        }
        
    }
Comment 1 Jan Becicka 2005-11-24 10:08:46 UTC
Please provide build # and steps to reproduce. I cannot reproduce it.
Comment 2 Tomas Hurka 2005-11-24 10:19:01 UTC
I cannot reproduce it in recent dev. build. Please provide more information how to reproduce it. Which 
build are you using? 
Comment 3 mazzuco 2005-11-24 10:22:28 UTC
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.
Comment 4 Jan Becicka 2005-11-24 12:48:31 UTC
Milane, can you test it?
Comment 5 Jan Becicka 2005-11-24 13:34:44 UTC
*** Issue 69185 has been marked as a duplicate of this issue. ***
Comment 6 Jan Becicka 2005-11-24 13:34:56 UTC
*** Issue 69107 has been marked as a duplicate of this issue. ***
Comment 7 Milan Kubec 2005-11-24 15:51:41 UTC
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.
Comment 8 mazzuco 2005-11-25 09:05:23 UTC
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.

Comment 9 mazzuco 2005-11-28 14:39:55 UTC
Created attachment 27339 [details]
example of code after the try-catch
Comment 10 mazzuco 2005-11-28 14:41:17 UTC
Created attachment 27340 [details]
the same code BEFORE making try-catch
Comment 11 mazzuco 2005-11-28 14:44:48 UTC
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
Comment 12 mazzuco 2005-11-28 14:48:23 UTC
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)
Comment 13 mazzuco 2005-11-28 14:52:36 UTC
Created attachment 27343 [details]
strange behaviour
Comment 14 Milan Kubec 2005-12-16 14:45:40 UTC
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.
Comment 15 Pavel Flaska 2005-12-22 10:38:43 UTC
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.
Comment 16 Pavel Flaska 2005-12-22 15:28:03 UTC
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
Comment 17 Milan Kubec 2006-01-03 13:38:42 UTC
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.
Comment 18 Milan Kubec 2006-01-03 13:39:11 UTC
Created attachment 28144 [details]
screenshot
Comment 19 Milan Kubec 2006-01-03 13:50:55 UTC
Not reproducible always.
Comment 20 Pavel Flaska 2006-01-03 16:40:01 UTC
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.
Comment 21 Pavel Flaska 2006-01-03 17:19:31 UTC
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
Comment 22 Milan Kubec 2006-01-04 12:33:50 UTC
Verified, I'm not able to reproduce the problem in trunk build 200601031900.
Comment 23 Milan Kubec 2006-01-05 11:05:34 UTC
Please, don't forget to get code review and commit the fix into release50
branch. Thanks.
Comment 24 Jan Becicka 2006-01-05 15:13:52 UTC
The fix is safe.
Comment 25 Pavel Flaska 2006-01-05 16:08:32 UTC
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
Comment 26 Milan Kubec 2006-01-09 15:04:59 UTC
Verified in release50-rc1.
Comment 27 Quality Engineering 2007-09-20 10:05:47 UTC
Reorganization of java component