[OT] JDK 1.6u2 and JFileChooser

Hi, sorry for bothering with something probably not IDEA related.

I'm trying to switch a personal project to 1.6 and just downloaded the latest (1.6u2b06 for windows XP).

My problem, it seems it's not possible anymore to create a JFile chooser, the creating thread blocks in the constructor and never returns !

Test class

public class TestJFileChooser {

public static void main(String[] args) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setSize(200,200);
fileChooser.showDialog(null, "Ouvrir");
}
}


when executing this (using IDEA 7051), it never gets to the second line and when doing a stack dump here is what I see

"main" prio=6 tid=0x002a7000 nid=0x102c waiting on condition
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for (a java.util.concurrent.FutureTask$Sync) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158) at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:747) at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:905) at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1217) at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:218) at java.util.concurrent.FutureTask.get(FutureTask.java:83) at sun.awt.shell.Win32ShellFolder2$ComTask.execute(Win32ShellFolder2.java:1214) at sun.awt.shell.Win32ShellFolder2.hasAttribute(Win32ShellFolder2.java:516) at sun.awt.shell.Win32ShellFolder2.isDirectory(Win32ShellFolder2.java:585) at sun.awt.shell.Win32ShellFolderManager2.get(Win32ShellFolderManager2.java:208) at sun.awt.shell.ShellFolder.get(ShellFolder.java:218) at javax.swing.plaf.metal.MetalFileChooserUI.updateUseShellFolder(MetalFileChooserUI.java:432) at javax.swing.plaf.metal.MetalFileChooserUI.installComponents(MetalFileChooserUI.java:189) at javax.swing.plaf.basic.BasicFileChooserUI.installUI(BasicFileChooserUI.java:136) at javax.swing.plaf.metal.MetalFileChooserUI.installUI(MetalFileChooserUI.java:124) at javax.swing.JComponent.setUI(JComponent.java:673) at javax.swing.JFileChooser.updateUI(JFileChooser.java:1762) at javax.swing.JFileChooser.setup(JFileChooser.java:360) at javax.swing.JFileChooser.(JFileChooser.java:333) at javax.swing.JFileChooser.]]>(JFileChooser.java:286)
at fagart.decompiler.bytecode.TestJFileChooser.main(TestJFileChooser.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)


Even more strange, i just noticed that the dialog eventually displays, after about 30s it seems.

DOes any of this make sense ??

7 comments
Comment actions Permalink

Hello Thibaut,

Swing stuff should now be done from the event dispatch thread. You should
surround the code in your main() with SwingUtilities.invokeLater().

Hi, sorry for bothering with something probably not IDEA related.

I'm trying to switch a personal project to 1.6 and just downloaded the
latest (1.6u2b06 for windows XP).

My problem, it seems it's not possible anymore to create a JFile
chooser, the creating thread blocks in the constructor and never
returns !

Test class

public class TestJFileChooser {

public static void main(String[] args) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setSize(200,200);
fileChooser.showDialog(null, "Ouvrir");
}
}
when executing this (using IDEA 7051), it never gets to the second
line and when doing a stack dump here is what I see

"main" prio=6 tid=0x002a7000 nid=0x102c waiting on condition

java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x229795d8> (a
java.util.concurrent.FutureTask$Sync)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
at
java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInte
rrupt(AbstractQueuedSynchronizer.java:747)
at
java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedI
nterruptibly(AbstractQueuedSynchronizer.java:905)
at
java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInt
erruptibly(AbstractQueuedSynchronizer.java:1217)
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:218)
at java.util.concurrent.FutureTask.get(FutureTask.java:83)
at
sun.awt.shell.Win32ShellFolder2$ComTask.execute(Win32ShellFolder2.java
:1214)
at
sun.awt.shell.Win32ShellFolder2.hasAttribute(Win32ShellFolder2.java:51
6)
at
sun.awt.shell.Win32ShellFolder2.isDirectory(Win32ShellFolder2.java:585
)
at
sun.awt.shell.Win32ShellFolderManager2.get(Win32ShellFolderManager2.ja
va:208)
at sun.awt.shell.ShellFolder.get(ShellFolder.java:218)
at
javax.swing.plaf.metal.MetalFileChooserUI.updateUseShellFolder(MetalFi
leChooserUI.java:432)
at
javax.swing.plaf.metal.MetalFileChooserUI.installComponents(MetalFileC
hooserUI.java:189)
at
javax.swing.plaf.basic.BasicFileChooserUI.installUI(BasicFileChooserUI
.java:136)
at
javax.swing.plaf.metal.MetalFileChooserUI.installUI(MetalFileChooserUI
.java:124)
at javax.swing.JComponent.setUI(JComponent.java:673)
at javax.swing.JFileChooser.updateUI(JFileChooser.java:1762)
at javax.swing.JFileChooser.setup(JFileChooser.java:360)
at javax.swing.JFileChooser.<init>(JFileChooser.java:333)
at javax.swing.JFileChooser.<init>(JFileChooser.java:286)
at
fagart.decompiler.bytecode.TestJFileChooser.main(TestJFileChooser.java
:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.j
ava:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess
orImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Even more strange, i just noticed that the dialog eventually displays,
after about 30s it seems.

DOes any of this make sense ??

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

wow i didn't know you even had to create frames or dialogs this way, thanks for the tip.

0
Comment actions Permalink

well just tried it, and in fact it doesn't solve it

"AWT-EventQueue-0" prio=6 tid=0x02b3a000 nid=0x1234 waiting on condition
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for (a java.util.concurrent.FutureTask$Sync) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158) at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:747) at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:905) at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1217) at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:218) at java.util.concurrent.FutureTask.get(FutureTask.java:83) at sun.awt.shell.Win32ShellFolder2$ComTask.execute(Win32ShellFolder2.java:1214) at sun.awt.shell.Win32ShellFolder2.hasAttribute(Win32ShellFolder2.java:516) at sun.awt.shell.Win32ShellFolder2.isDirectory(Win32ShellFolder2.java:585) at sun.awt.shell.Win32ShellFolderManager2.get(Win32ShellFolderManager2.java:208) at sun.awt.shell.ShellFolder.get(ShellFolder.java:218) at javax.swing.plaf.metal.MetalFileChooserUI.updateUseShellFolder(MetalFileChooserUI.java:432) at javax.swing.plaf.metal.MetalFileChooserUI.installComponents(MetalFileChooserUI.java:189) at javax.swing.plaf.basic.BasicFileChooserUI.installUI(BasicFileChooserUI.java:136) at javax.swing.plaf.metal.MetalFileChooserUI.installUI(MetalFileChooserUI.java:124) at javax.swing.JComponent.setUI(JComponent.java:673) at javax.swing.JFileChooser.updateUI(JFileChooser.java:1762) at javax.swing.JFileChooser.setup(JFileChooser.java:360) at javax.swing.JFileChooser.(JFileChooser.java:333) at javax.swing.JFileChooser.]]>(JFileChooser.java:286)
at fagart.decompiler.bytecode.TestJFileChooser$1.run(TestJFileChooser.java:18)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.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)

0
Comment actions Permalink

It is a bug in the JDK. JFileChooser is known to be extremely slow under java 1.6.0_02
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6578753

Bas

0
Comment actions Permalink

wow i didn't know you even had to create frames or dialogs this way, thanks for the tip.


As long as the components (e.g. frame or dialog) is not visible on the
screen, you don't need to use the EventDispatchThread.

0
Comment actions Permalink

wow i didn't know you even had to create frames or dialogs this way, thanks for the tip.


As long as the components (e.g. frame or dialog) is not visible on the
screen, you don't need to use the EventDispatchThread.


Apparently these days it is recommended to construct swing components on the event dispatch thread also:
http://weblogs.java.net/blog/alexfromsun/archive/2006/02/debugging_swing.html
http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html

Bas

0
Comment actions Permalink

thx , indeed it seems to explain what i see (>30s to create a JFileChooser instance)

Message was edited by:
Thibaut

0

Please sign in to leave a comment.