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 142242

Summary: try-catch hint for block generates strange code
Product: editor Reporter: Lukas Hasik <lhasik>
Component: Hints & AnnotationsAssignee: issues@editor <issues>
Status: RESOLVED DUPLICATE    
Severity: blocker CC: mmirilovic
Priority: P2    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description Lukas Hasik 2008-07-30 15:02:28 UTC
Product Version: NetBeans IDE Dev (Build 080730)
Java: 1.5.0_14; Java HotSpot(TM) Client VM 1.5.0_14-b03
System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb)
Userdir: F:\hg\main\nbbuild\testuserdir

1, I have code like
        FileInputStream fis = new FileInputStream(filename);
        int x = fis.available();
        byte b[] = new byte[x];
        fis.read(b);
        String content = new String(b);
        System.out.println(content);
2, use hint "Surround \block with try-catch" on the first line

-> result looks strange, why there is the "try { fis = null" ?

        FileInputStream fis = null;
        try {
            fis = null;
        try {
            fis = new FileInputStream(filename);
            
            int x = fis.available();
            
            byte[] b b = new byte[x];
            
            fis.read(b);
            String content = new String(b);
            System.out.println(content);
        } catch (FileNotFoundException ex) {
            Exceptions.printStackTrace(ex);
        } finally {
            try {
                fis.close();
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
            String content = new String(b);
            System.out.println(content);
        } catch (FileNotFoundException ex) {
            Exceptions.printStackTrace(ex);
        } finally {
            try {
                fis.close();
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
Comment 1 Marian Mirilovic 2008-07-30 15:23:41 UTC
Dup of issue 142199 ?
Comment 2 Jiri Prox 2008-07-31 08:07:22 UTC
Yes, it's dup of issue 142199. I cannot reproduce now when 142199 is fixed

*** This issue has been marked as a duplicate of 142199 ***