Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayIndexOutOfBoundsException in WebFileChooser #121

Closed
moizhb opened this issue May 15, 2014 · 4 comments
Closed

ArrayIndexOutOfBoundsException in WebFileChooser #121

moizhb opened this issue May 15, 2014 · 4 comments
Assignees

Comments

@moizhb
Copy link

moizhb commented May 15, 2014

While instantiating WebFileChooser I get the following error. Interestingly, I do not see this error every time. but it does happen 1 in 20 times.

Usage: fileChooser = new WebFileChooser();

Error:
java.lang.ArrayIndexOutOfBoundsException: 3
at com.alee.utils.FileUtils.getDiskRoots(FileUtils.java:375)
at com.alee.extended.filechooser.WebPathField.(WebPathField.java:101)
at com.alee.laf.filechooser.WebFileChooserPanel.createNorthContent(WebFileChooserPanel.java:432)
at com.alee.laf.filechooser.WebFileChooserPanel.(WebFileChooserPanel.java:297)
at com.alee.laf.filechooser.WebFileChooserUI.installUI(WebFileChooserUI.java:108)
at javax.swing.JComponent.setUI(JComponent.java:664)
at com.alee.laf.filechooser.WebFileChooser.updateUI(WebFileChooser.java:308)
at javax.swing.JFileChooser.setup(JFileChooser.java:370)
at javax.swing.JFileChooser.(JFileChooser.java:352)
at javax.swing.JFileChooser.(JFileChooser.java:311)
at com.alee.laf.filechooser.WebFileChooser.(WebFileChooser.java:58)

@mgarin
Copy link
Owner

mgarin commented May 15, 2014

This happends in this method:

    public static File[] getDiskRoots ()
    {
        final File[] roots = File.listRoots ();
        int proper = 0;
        for ( final File root : roots )
        {
            if ( root.isDirectory () )
            {
                proper++;
            }
        }
        final File[] properRoots = new File[ proper ];
        int currentIndex = 0;
        for ( final File root : roots )
        {
            if ( root.isDirectory () )
            {
                properRoots[ currentIndex ] = root;
                currentIndex++;
            }
        }
        return properRoots;
    }

My guess is that sometimes your file system (well yeh, I have never seens this exception on any of my machines with different OS) returns different value for isDirectory () call. This might happen due to some new JDK bugs (or old ones) or due to your specific system.

In any case - I'll just reduce this method usage to one call and it will be fixed. Thanks for pointing out this possible issue :)

I will include this fix into v1.28 update.

@mgarin mgarin added this to the Small issues milestone May 15, 2014
@mgarin mgarin self-assigned this May 15, 2014
mgarin added a commit that referenced this issue May 18, 2014
#121 - Small fix for FileUtils.getDiskRoots() method
WebDocumentPane custom component added (will be completed in v1.28 release)
DragManager preview added
PopupMenuGenerator preview added
Main README updated with more screenshots
Screenshots moved into a separate directory
@moizhb
Copy link
Author

moizhb commented May 19, 2014

Thanks alot quick response.!

@mgarin
Copy link
Owner

mgarin commented May 20, 2014

All changes are available in sources so you can build temporary library version using provided ANT script if you want to test it out right away or you can wait for v1.28 release which will include it.

@mgarin mgarin added the fixed label Jun 26, 2014
@mgarin
Copy link
Owner

mgarin commented Jun 26, 2014

Fix is now available in v1.28 update:
https://github.com/mgarin/weblaf/releases/tag/v1.28

@mgarin mgarin closed this as completed Jun 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants