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.
I have found a case in which the "Introduce Method" refactoring generates invalid code. It appears to have a problem when a single statement declares several variables, such as: double foo, bar, baz, bat, wuux; To reproduce this, add the following code to a method within a Java class (I used the main method for a newly-generated class: double leftH, rightH, delta, deltaY; double tLeft, tRight, bLeft, bRight; tLeft = 3.4; tRight = 4.5; bLeft = 5.6; bRight = 6.7; leftH = Math.max(tLeft, bLeft); rightH = Math.max(tRight, bRight); delta = rightH - leftH; Highlight all of this code and right-click, then select Refactor -> Introduce Method from the popup menu. Type a name for the new method (I used "foo") and click OK on the dialog. This generates the following new method: private static void foo(double rightH, double leftH) { double delta; double leftH, rightH, delta, deltaY; double tLeft, double tLeft, tRight, double tLeft, tRight, bLeft, double tLeft, tRight, bLeft, bRight; tLeft = 3.4; tRight = 4.5; bLeft = 5.6; bRight = 6.7; leftH = Math.max(tLeft, bLeft); rightH = Math.max(tRight, bRight); delta = rightH - leftH; } As you can see, the tLeft variable is declared multiple times and all of these except for the last are invalid statements since they do not conclude with a semicolon.
I have confirmed that declaring each variable on its own line works around this bug in NetBeans.
implemented in hints module.
http://hg.netbeans.org/jet-main/rev/77fa3b1a6c65
Integrated into 'main-golden' Changeset: http://hg.netbeans.org/main-golden/rev/77fa3b1a6c65 User: Jan Lahoda <jlahoda@netbeans.org> Log: #203002: fixing handling of field groups inside the introduce method hint.
I verified this using the most recent nightly build: Product Version: NetBeans IDE Dev (Build 201110250600) Java: 1.6.0_25; Java HotSpot(TM) Client VM 20.0-b11 System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb) Thanks for the quick fix!