United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6342641 ArrayIndexOutOfBoundException when moving Swing app into secondary monitor
6342641 : ArrayIndexOutOfBoundException when moving Swing app into secondary monitor

Details
Type:
Bug
Submit Date:
2005-10-27
Status:
Closed
Updated Date:
2010-04-02
Project Name:
JDK
Resolved Date:
2007-02-15
Component:
client-libs
OS:
windows_xp
Sub-Component:
2d
CPU:
x86
Priority:
P3
Resolution:
Duplicate
Affected Versions:
6
Fixed Versions:

Related Reports
Duplicate:
Relates:

Sub Tasks

Description
Steps to reproduce:
1) Configure your Win XP so that it's using just one primary monitor, have secondary monitor available but disabled.
2) Run SwingSet2 demo application
3) Enable secondary display in OS settings, wait for display to enlightent itself :-)
4) Drag SwingSet2 window to secondary monitor area

Result: AIOOBE thrown:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException:
 1
        at sun.awt.windows.WWindowPeer.updateGC(WWindowPeer.java:264)
        at sun.awt.windows.WWindowPeer.displayChanged(WWindowPeer.java:291)
        at sun.awt.windows.WWindowPeer$1.run(WWindowPeer.java:235)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:173)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

                                    

Comments
EVALUATION

This bug is covered by the fix for
  4417798: Need to track add/remove of monitors on display changes
so I'm closing it as a duplicate.
                                     
2007-02-15
SUGGESTED FIX

*** /tmp/geta19825	 28 15:05:13 2005
--- awt_Win32GraphicsEnv.cpp	28 15:05:07 2005
***************
*** 92,97 ****
--- 92,98 ----
  
  int getScreenFromMHND(MHND mon) {
      DASSERT(mon != NULL);
+     awt_numScreens = ::CountMonitors();
  
      for (int i = 0; i < awt_numScreens; i++) {
          if (areSameMonitors(mon, getMHNDFromScreen(i))) {
                                     
2005-10-28
EVALUATION

I'm unable to reproduce the whole scenario but looking on the sources may predict the wrong place.
WWindowPeer accessing an array of Screens:
Win32GraphicsDevice newDev = (Win32GraphicsDevice)GraphicsEnvironment            .getLocalGraphicsEnvironment().getScreenDevices()[scrn];

scrn is actually == awt_Window:GetScreenImOn() and in turn scrn == getScreenFromMHND(hmon);

We use  awt_numScreens variable in getScreenFromMHND(hmon) to through all monitors but seems that variable is only initializes here:
void initScreens(JNIEnv *env) {
    awt_numScreens = ::CountMonitors();
....

Not sure if calling that method before counting again will solve the problem - should run application to verify.
                                     
2005-10-28
EVALUATION

This is a known issue - see 4417795. The problem here is that we need not to simply update the number of monitors present in the system each time we access them, but to create a new drawing surface for them, init DirectX and many other things.
                                     
2005-10-28



Hardware and Software, Engineered to Work Together