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 116456 - Netbeans 6.0 Beta 1 attempts to add a method inside another one
Summary: Netbeans 6.0 Beta 1 attempts to add a method inside another one
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker with 1 vote (vote)
Assignee: Jan Pokorsky
URL:
Keywords:
: 121178 121281 121329 122714 126878 128267 128567 130333 131562 137638 138384 140360 143325 143539 147115 147437 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-09-23 23:02 UTC by alosii
Modified: 2008-09-24 18:36 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
The gray lines indicating the auto-generated code are wrong (223.80 KB, image/png)
2007-09-23 23:05 UTC, alosii
Details
The code after moving the "//GEN-LAST.." via a text editor (41.73 KB, image/png)
2007-09-24 18:09 UTC, alosii
Details
before, reformatting code (notice the wrong guidelines) (29.20 KB, image/png)
2007-09-25 20:16 UTC, alosii
Details
after the reformat (30.28 KB, image/png)
2007-09-25 20:18 UTC, alosii
Details

Note You need to log in before you can comment on or make changes to this bug.
Description alosii 2007-09-23 23:02:03 UTC
Netbeans 6.0 Beta 1 attempts to add a method inside another one:

While building a GUI sometimes adding a method to a button will place the auto-generated inside another method generating several error and corrupting 
the file.
Comment 1 alosii 2007-09-23 23:05:04 UTC
Created attachment 49331 [details]
The gray lines indicating the auto-generated code are wrong
Comment 2 ehucka 2007-09-24 12:24:08 UTC
Could you describe step by step how to reproduce it? thanks
Comment 3 alosii 2007-09-24 18:05:54 UTC
I haven't been able to reproduce it. But I found a way to fix it =)

Opening the class in a text editor and placing the:

//GEN-LAST:event_racionalesEjericiosBotonActionPerformed

In the correct bracket ( } ) fixed the problem....sort of...now the method has no gray lines but the IDE will insert new methods right after the last one with 
correct "gray lines"

BEFORE:

    private void racionalesEjericiosBotonActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_racionalesEjericiosBotonActionPerformed                                                        
        try {
            String aux = controlRacional.parseadorDeRacionales(this.racionalesEjericiosOperacionesText.getText()).toString();
            this.racionalesEjerciciosArea.setText(aux);//GEN-LAST:event_ racionalesEjericiosBotonActionPerformed                                                        
        } catch (ErrorEnCadenaException ex) {
            Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
        }
    }  


AFTER:

    private void racionalesEjericiosBotonActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_racionalesEjericiosBotonActionPerformed                                                        
        try {
            String aux = controlRacional.parseadorDeRacionales(this.racionalesEjericiosOperacionesText.getText()).toString();
            this.racionalesEjerciciosArea.setText(aux);                                                      
        } catch (ErrorEnCadenaException ex) {
            Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_ racionalesEjericiosBotonActionPerformed    
Comment 4 alosii 2007-09-24 18:09:08 UTC
Created attachment 49377 [details]
The code after moving the "//GEN-LAST.." via a text editor
Comment 5 Tomas Pavek 2007-09-24 18:33:09 UTC
Yes, it is clear what is wrong - and the way you fixed it is correct.
Do you remember which method (even handler) you've added when the problem happened?
Did anything like this happen more than once to you?
Comment 6 alosii 2007-09-24 18:46:17 UTC
At first i thought it had something to do with using the tips (the little light bulb) to auto-wrap an instruction in a try-catch block and the IDE wont count these 
extra lines into de mix....but  i haven't been able to do it again....I'll post again if I find out whats wrong.
Comment 7 alosii 2007-09-24 18:51:40 UTC
It was an ActionPerformed event for a JButton...
Comment 8 Tomas Pavek 2007-09-25 15:36:24 UTC
Actually it makes more sense this was was caused by using the "Surround with try-catch" feature. It might somehow mis-
place the ending guarded block comment. I can't imagine how adding another event handler could cause this - it just 
creates a new guarded section, does not change existing ones.

Reassigning to java/source guys if they have some idea. But we'd definitely welcoem the exact steps to reproduce the 
problem.
Comment 9 alosii 2007-09-25 20:14:27 UTC
Im posting this here and not as a separate problem because i think its related, after selecting a few lines of code and using the "Reformat code" some of my 
code will disappear for no reason. See the before and after picture, notice the "collapsable" guides on the left are totally wrong on the before picture. This is 
on the same file where I've been having problems. I think something is seriously wrong =(


Comment 10 alosii 2007-09-25 20:16:03 UTC
Created attachment 49508 [details]
before, reformatting code (notice the  wrong guidelines)
Comment 11 alosii 2007-09-25 20:18:20 UTC
Created attachment 49509 [details]
after the reformat
Comment 12 Jiri Prox 2007-09-26 11:39:57 UTC
The second problem (desc10,11,12) is not related to the first one so I've filed it as separate issue 116807. But I
cannot see what is wrong on the "before" picture.
Comment 13 Tomas Pavek 2007-11-05 15:43:02 UTC
*** Issue 121178 has been marked as a duplicate of this issue. ***
Comment 14 Tomas Pavek 2007-11-07 11:10:07 UTC
*** Issue 121329 has been marked as a duplicate of this issue. ***
Comment 15 Tomas Pavek 2007-11-07 13:03:41 UTC
*** Issue 121329 has been marked as a duplicate of this issue. ***
Comment 16 Tomas Pavek 2007-11-07 13:06:09 UTC
*** Issue 121281 has been marked as a duplicate of this issue. ***
Comment 17 denismoinel 2007-12-30 13:27:17 UTC
Hi, 
I also encountered the same problem.
The IDE will insert a function in another function.
Here is the code displayed with an external editor: the //GEN-LAST:event_gradientViewer1MouseDragged is not at the 
good place. I cannot reproduce the problem, but I can say that I've played with comments of code (/* ... */) before 
the bug occurs. I also added a @SuppressWarnings("static-access") with the automatic corrector.

Product Version: NetBeans IDE 6.0 (Build 200711261600)
Java: 1.6.0; Java HotSpot(TM) Client VM 1.6.0-b105
System: Linux version 2.6.20-16-generic running on i386; UTF-8; fr_FR (nb)


 @SuppressWarnings("static-access")
    private void gradientViewer1MouseDragged(java.awt.event.MouseEvent evt) 
{//GEN-FIRST:event_gradientViewer1MouseDragged
        // TODO add your handling code here:
         JLabel labelXY=null;//GEN-LAST:event_gradientViewer1MouseDragged
        int button = evt.getButton();
        Point p = evt.getPoint();
        p.x = p.x - gradientViewer1.getWidth()/2; // pour mettre l'origine au centre
        p.y = p.y - gradientViewer1.getHeight()/2;// pour mettre l'origine au centre
        String s = String.valueOf("x="+p.x)+" y="+String.valueOf(p.y);
        jLabel3.setText(s);
        //if (button==evt.BUTTON1){
        if (SwingUtilities.isLeftMouseButton(evt)){
            labelXY=jLabelPoint1;
            changeGradient(p,
                    gradientViewer1.getGradient().getColor1(),
                    gradientViewer1.getGradient().getPoint2(),
                    gradientViewer1.getGradient().getColor2(),false);
        }
        //else if (button==evt.BUTTON3){
        else if (SwingUtilities.isRightMouseButton(evt)){            
            labelXY=jLabelPoint2;
            changeGradient(gradientViewer1.getGradient().getPoint1(),
                    gradientViewer1.getGradient().getColor1(),
                    p,
                    gradientViewer1.getGradient().getColor2(),false);
        }
        if (labelXY!=null){
            //String s;
            s  = "  x = " + String.valueOf(p.getX());
            s += "  y = " + String.valueOf(p.getY());
            labelXY.setText(s);
        }
    }
Comment 18 Jan Becicka 2008-01-31 09:08:08 UTC
code generator issue
Comment 19 Jan Lahoda 2008-02-08 17:04:20 UTC
*** Issue 126878 has been marked as a duplicate of this issue. ***
Comment 20 Jan Lahoda 2008-02-14 16:07:13 UTC
Actually, it turns out that the root cause is not in the codegen. The problem can be reproduced manually. The steps to
reproduce are:
1. Start the IDE, create a new J2SE project
2. Create a new JPanel form
3. Drag and drop JButton into the form, right click the added button, choose Events/Action/actionPerformed - the
generated handler will be opened in the editor.
4a. either: replace the autogenerated comment with "new FileOutputStream("").write(0);", resolve imports, and choose
Surround block with try-catch
4b. or: place caret at the very first offset at the last line of the handler method (the line is guarded) and press "enter".
5. save and close the file and reopen it - the guarded block ends at wrong place

The problem seems to be caused by Positions inconsistency in the InteriorSectionImpl - after step 4a or 4b, the "body"
positions bound is not immediately followed by the "footer" positions bound. And the (wrong) "body" positions are then
used to generate the "guard" comments when the file is being saved.
Comment 21 Jan Stola 2008-02-26 13:43:19 UTC
*** Issue 128267 has been marked as a duplicate of this issue. ***
Comment 22 Jan Lahoda 2008-02-27 15:15:59 UTC
*** Issue 128567 has been marked as a duplicate of this issue. ***
Comment 23 Jan Stola 2008-03-19 11:58:29 UTC
*** Issue 130333 has been marked as a duplicate of this issue. ***
Comment 24 Jan Stola 2008-04-01 16:28:42 UTC
*** Issue 131562 has been marked as a duplicate of this issue. ***
Comment 25 Jiri Prox 2008-04-11 00:52:18 UTC
moving opened issues from TM <= 6.1 to TM=Dev
Comment 26 Jan Stola 2008-06-19 07:57:11 UTC
*** Issue 137638 has been marked as a duplicate of this issue. ***
Comment 27 lordthecrow 2008-06-19 09:59:27 UTC
I had the same problem, but my pattern doesn't fit in  jlahoda steps. (------- Additional comments from jlahoda Thu Feb
14 16:07:13 +0000 2008 -------). I had no buttons in my forms. I just played with menu items and a lot of try catch.
Unfortunately I cannot reproduce it, by I could correct it fallowing the posts.
Comment 28 Jan Stola 2008-06-19 10:10:42 UTC
In fact, lordthecrow's use-case matches exactly this issue. This problem, of course, is not button specific. The key 
ingredients seem to be the generation of an event handler for some event of some component and invocation of Surround 
with try-catch.
Comment 29 Jana Maleckova 2008-06-19 10:29:11 UTC
I think the priority of this issue is not appropriate and should be increased. It is simply reproducible and
consequences are very bad. The number of duplicates is raising as well. Therefore I set priority as P2
Comment 30 Jan Pokorsky 2008-06-19 10:50:54 UTC
janie: Is it really simply reproducible? Could you share your test case please? In duplicates you can read that it
happened but I cannot find steps how to reproduce. Even jlahoda has not been able to reproduce it again.
Comment 31 Jiri Prox 2008-06-19 11:20:00 UTC
I can reproduce it as well, following Honza's steps to reproduce (desc21)

Product Version: NetBeans IDE Dev (Build 20080618044251)
Java: 1.6.0_10-beta; Java HotSpot(TM) Client VM 11.0-b12
System: Linux version 2.6.22-14-generic running on i386; UTF-8; en_US (nb)
Comment 32 Jana Maleckova 2008-06-19 11:27:44 UTC
I followed the steps described by jlahoda and it's reproducible as well (windows XP, trunk Build 20080619).
Comment 33 Jan Pokorsky 2008-06-24 12:33:15 UTC
It looks that the java source generator removes end part of the body of the interior guarded section while generating
try/catch block. I will fix guarded section's positions to survive such a manipulation.
Comment 34 Jan Pokorsky 2008-06-24 13:32:44 UTC
*** Issue 122714 has been marked as a duplicate of this issue. ***
Comment 35 Jan Pokorsky 2008-06-25 16:26:13 UTC
fixed as http://hg.netbeans.org/main/rev/0ee22aad73ba
Comment 36 Jiri Vagner 2008-06-27 06:29:32 UTC
*** Issue 138384 has been marked as a duplicate of this issue. ***
Comment 37 Quality Engineering 2008-06-27 16:09:58 UTC
Integrated into 'main-golden', available in NB_Trunk_Production #285 build
Changeset: http://hg.netbeans.org/main/rev/0ee22aad73ba
User: Jan Pokorsky <jpokorsky@netbeans.org>
Log: #116456: introduced BiasedPosition to guarantee the position survives insert/remove operations properly
Comment 38 Jiri Prox 2008-07-28 12:23:03 UTC
*** Issue 140360 has been marked as a duplicate of this issue. ***
Comment 39 Jiri Prox 2008-08-11 08:44:47 UTC
*** Issue 143325 has been marked as a duplicate of this issue. ***
Comment 40 Jiri Vagner 2008-08-12 07:45:12 UTC
*** Issue 143539 has been marked as a duplicate of this issue. ***
Comment 41 Jiri Prox 2008-09-15 09:42:53 UTC
*** Issue 147115 has been marked as a duplicate of this issue. ***
Comment 42 Tomas Pavek 2008-09-24 18:36:41 UTC
*** Issue 147437 has been marked as a duplicate of this issue. ***