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 99010 - Adding try/catch block can mangle or remove code
Summary: Adding try/catch block can mangle or remove code
Status: RESOLVED DUPLICATE of bug 92317
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 6.x
Hardware: PC All
: P2 blocker (vote)
Assignee: issues@java
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-03-26 16:50 UTC by tomwheeler
Modified: 2007-09-26 09:14 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tomwheeler 2007-03-26 16:50:34 UTC
Using NetBeans 6.0 milestone 7 on Windows XP under Java 6, I wrote the following
code inside the performAction of CookieAction class:

        Node node = (Node) activatedNodes[0].getLookup().lookup(Object.class);
        Lookup theLookup = node.getLookup();
            
        System.out.println("Dumping Lookup...");
        InstanceCookie ic = (InstanceCookie) theLookup.lookup(InstanceCookie.class);
            
        if (DogBean.class.equals(ic.instanceClass())) {
            DogBean dog1 = (DogBean) ic.instanceCreate();
                
            System.out.println("  Dog Name =>   " + dog1.getName());
        }

This code can throw can IOException, so I clicked the "lightbulb" icon to fix
the code by surrounding the code with a try/catch block.  When I do this, the
code switches to using unnecessary fully-qualified classnames:

        try     {
            org.openide.nodes.Node node = (org.openide.nodes.Node)
activatedNodes[0].getLookup().lookup(java.lang.Object.class);
            org.openide.util.Lookup theLookup = node.getLookup();

            java.lang.System.out.println("Dumping Lookup...");
            org.openide.cookies.InstanceCookie ic =
(org.openide.cookies.InstanceCookie)
theLookup.lookup(org.openide.cookies.InstanceCookie.class);

            if
(com.example.beannodeexample.DogBean.class.equals(ic.instanceClass())) {
                com.example.beannodeexample.DogBean dog1 =
(com.example.beannodeexample.DogBean) ic.instanceCreate();

                java.lang.System.out.println("  Dog Name =>   " + dog1.getName());
            }
        }
        catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
        catch (ClassNotFoundException ex) {
            Exceptions.printStackTrace(ex);
        }


I did something similar last week and, instead of doing that, it actually
deleted my code entirely.  Unfortunately, I was interrupted before I could log
the exact circumstances.
Comment 1 Jiri Prox 2007-03-26 17:10:41 UTC
It's duplicate of issue 92317. Thanks for your report.

*** This issue has been marked as a duplicate of 92317 ***
Comment 2 Pavel Flaska 2007-07-10 15:56:01 UTC
        Node node = (Node) activatedNodes[0].getLookup().lookup(Object.class);
        Lookup theLookup = node.getLookup();
            
        System.out.println("Dumping Lookup...");
        InstanceCookie ic = (InstanceCookie) theLookup.lookup(InstanceCookie.class);
            
        if (DogBean.class.equals(ic.instanceClass())) {
            DogBean dog1 = (DogBean) ic.instanceCreate();
                
            System.out.println("  Dog Name =>   " + dog1.getName());
        }

->
    void m() {
        try {
            Node[] activatedNodes = null;
            Node node = (Node) activatedNodes[0].getLookup().lookup(Object.class);
            Lookup theLookup = node.getLookup();

            System.out.println("Dumping Lookup...");
            InstanceCookie ic = theLookup.lookup(InstanceCookie.class);

            if (DogBean.class.equals(ic.instanceClass())) {
                DogBean dog1 = (DogBean) ic.instanceCreate();

                System.out.println("  Dog Name =>   " + dog1.getName());
            }
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        } catch (ClassNotFoundException ex) {
            Exceptions.printStackTrace(ex);
        }
        
    }

Array is duplicated, but it is another problem, will be reported separately.