Bug 531

Summary: get*Listeners methods from GLWindow throw ClassCast exceptions
Product: [JogAmp] Newt Reporter: Sebastien Schneider <sebastien.schneider>
Component: coreAssignee: Sven Gothel <sgothel>
Status: RESOLVED FIXED    
Severity: normal CC: gouessej, sebastien.schneider, sgothel
Priority: ---    
Version: 1   
Hardware: All   
OS: all   
Type: --- SCM Refs:
jogl 927521af10162f2bf8c02b12cce75bd7de71dafe
Workaround: ---

Description Sebastien Schneider 2011-12-02 11:39:04 CET
When I call getMouseListeners or getWindowListeners or getKeyListeners ... on a NEWT GLWindow I get a java ClassCastException that says that a Java Object array cannot be cast to a NEWT Listener array:
[Ljava.lang.Object; cannot be cast to [Lcom.jogamp.newt.event.MouseListener; in the case of the GLWindow.getMouseListeners()
Comment 1 Sebastien Schneider 2011-12-02 11:42:28 CET
change JOGL product to NEWT product
Comment 2 Julien Gouesse 2011-12-15 21:21:20 CET
Hi

For example, getWindowListeners() should not use toArray() because it returns Object[] instead of WindowListener[].

This method:
public WindowListener[] getWindowListeners() {
    return (WindowListener[]) windowListeners.toArray();
}

should be replaced by this one:
public WindowListener[] getWindowListeners() {
    return windowListeners.toArray(new WindowListener[windowListeners.size]);
}

There is the same bug with getKeyListeners(). If you don't want to use <T> T[] toArray(T[] a), just use a simple loop. Best regards.
Comment 3 Sven Gothel 2011-12-18 17:11:28 CET
fixed - thx.