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

Summary: Adding try/catch block can mangle or remove code
Product: java Reporter: tomwheeler <tomwheeler>
Component: UnsupportedAssignee: issues@java <issues>
Status: RESOLVED DUPLICATE    
Severity: blocker    
Priority: P2    
Version: 6.x   
Hardware: PC   
OS: All   
Issue Type: DEFECT Exception Reporter:

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.