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 268263 - MultiViewCloneableEditor.canCloseElement() doesn't use the attached Savable
Summary: MultiViewCloneableEditor.canCloseElement() doesn't use the attached Savable
Status: NEW
Alias: None
Product: ide
Classification: Unclassified
Component: Code (show other bugs)
Version: 8.0.2
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: issues@ide
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-29 07:43 UTC by Yann_Dameron
Modified: 2016-09-29 07:43 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 Yann_Dameron 2016-09-29 07:43:08 UTC
http://forums.netbeans.org/viewtopic.php?t=66935

Looking at the source code of the MultiViewCloneableEditor.canCloseElement(), I found a potential bug for which I'd like to get your inputs.

Current source code:
        Savable sav = getLookup().lookup(Savable.class);
        if (sav != null) {
            AbstractAction save = new AbstractAction() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        sup.saveDocument();
                    } catch (IOException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }
            };

We retrieve the Savable object from the Lookup but we don't use it to perform the save. This looks weird and could lead to some unexpected behaviour.
In my application, the Savable object retrieved by the lookup is performing more checks than the saveDocument but it is not triggered when the User close the editor with pending changes.

I'd like to submit the following patch but I'd like to be sure I understood correctly.

        final Savable sav = getLookup().lookup(Savable.class);
        if (sav != null) {
            AbstractAction save = new AbstractAction() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        sav.sav();
                    } catch (IOException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }
            };