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 122731

Summary: regression? Result of "Surround with try" is different from 5.5.1
Product: java Reporter: Masaki Katakai <masaki>
Component: EditorAssignee: Dusan Balek <dbalek>
Status: RESOLVED FIXED    
Severity: blocker CC: jf4jbug
Priority: P3    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description Masaki Katakai 2007-11-26 03:41:42 UTC
NetBeans 6.0 RC2:

The behavior of "Surround with try {..." is different from NetBeans 5.5.1.
In NB5.5.1, "int a;" will be moved to outside try {}.

Source :
--
public class Main {
    public Main() {
        int a = Integer.parseInt("5");
        System.out.println(a);
    }
}
--

Result NB6.0:
--
public class Main {
    public Main() {
        try {
            int a = Integer.parseInt("5");

        } catch (NumberFormatException numberFormatException) {
        }

        System.out.println(a);
    }
}
--

Result NB5.5.1:
--
public class Main {
    public Main() {
        int a;
        try {
            a = Integer.parseInt("5");
        } catch (NumberFormatException ex) {
            ex.printStackTrace();
        }
        System.out.println(a);
    }
}
--
Comment 1 Masaki Katakai 2007-11-26 03:43:38 UTC
Try "Surround with" for the line "        int a = Integer.parseInt("5");"
Comment 2 Jan Lahoda 2007-11-26 08:51:14 UTC
This relates to the Surround with try-catch hint (code template).
Comment 3 Dusan Balek 2007-11-29 14:39:06 UTC
Fixed. Selection template processing mechanism improved to move used variable declaration outside of blocks.

Checking in JavaCodeTemplateProcessor.java;
/cvs/java/editor/src/org/netbeans/modules/editor/java/JavaCodeTemplateProcessor.java,v  <--  JavaCodeTemplateProcessor.java
new revision: 1.20; previous revision: 1.19
done