Skip to content

[Swing|SWT]WLXPlugin.listCloseWindow(int) doesn't remove Shell/JFrame from internal HashTable #14

@meisl

Description

@meisl

Found just by looking at it (ie. haven't tried nor seen it fail). Oh, and Ken gave me a hint that there might be something wrong with types in somewhere in the wlx package:

I think a newer version should make use of javafx for the wlxplugin and there is a bug
somewhere in the wlxpluginadapter which should be visible if you would use type-safe
expressions.

Code looks like this:
in SWTWLXPlugin:

public final void listCloseWindow(final int listWin) {
    listCloseWindow();
    synchronized (shells) {
        Shell shell = (Shell) shells.get(listWin); // <<< unnecessary cast
        shells.remove(shell); // <<<<<<<<<<<<<<<<<<<<< should be listWin
        shell.dispose();
    }
}

...and in SwingWLXPlugin:

public final void listCloseWindow(final int listWin) {
    synchronized (frames) {
        // get JFrame identified by HWND
        final JFrame jframe = (JFrame) frames.get(new Integer(listWin)); // <<< unnecessary cast and boxing
        // remove stored JFrame instance, it is no longer used
        frames.remove(jframe); // <<<<<<<<<<<<<<<<<<<<< should be listWin
        // use seperate thread to call listClose (it could last a while)
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                // uninitialize the JFrame lister window contents
                listCloseWindow(jframe);
                // dispose the JFrame (it is no longer used)
                jframe.dispose();
            }
        });
    }
}

shells/frames is (should be) a Hashtable<Integer, Shell>/Hashtable<Integer, JFrame> so we should really pass an int (auto-boxed to Integer) to .remove rather than a Shell/JFrame, shouldn't we?

Note: the signature of java.util.Hashtable<K,V>.remove is: remove(Object key) - so the type system won't help us here. For what reason I don't know...

TODO: test-cases

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions