Benoker / DockingFrames

http://www.docking-frames.org
96 stars 46 forks source link

[Bug] Does not work with AdoptOpenJDK 16 on Windows #70

Closed enwi closed 3 years ago

enwi commented 3 years ago

Using this library with AdoptOpenJDK 16 on Windows results in a StringIndexOutOfBoundsException

java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 2
        at java.base/java.lang.String.checkBoundsBeginEnd(Unknown Source)
        at java.base/java.lang.String.substring(Unknown Source)
        at bibliothek.gui.DockUI.registerColors(DockUI.java:169)
        at bibliothek.gui.DockUI.<init>(DockUI.java:133)
        at bibliothek.gui.DockUI.getDefaultDockUI(DockUI.java:120)
        at bibliothek.gui.DockController.<clinit>(DockController.java:145)
        ... 22 more

The code part in question is:

    private void registerColors(){
        registerColors( ".+", new DefaultLookAndFeelColors() );

        String version = System.getProperty( "java.version" );
        int begin = version.indexOf( '.' ) + 1;
        int end = version.indexOf( '.', begin );
        int major = Integer.parseInt( version.substring( begin, end ));

        if( major >= 7 ){
            registerColors( "javax\\.swing\\.plaf\\.nimbus\\.NimbusLookAndFeel", new Nimbus6u10() );
        }
        else{
            registerColors( "com\\.sun\\.java\\.swing\\.plaf\\.nimbus\\.NimbusLookAndFeel", new Nimbus6u10() );
        }
        registerColors( "com\\.sun\\.java\\.swing\\.plaf\\.windows\\.WindowsLookAndFeel", new Windows() );
    }

Version is in this case 16, thus the part parsing the major version fails, while also being falsely implemented. The Version is normally in the form of Majo.Minor.Build, but in this case there is only the Major part.

Benoker commented 3 years ago

Thanks for asking. I did not yet have a good reason to checkout JDK16 :-)

This piece of code triggering the exception does no longer exist, it was replaced by something more robust: here is the link to the current implementation https://github.com/Benoker/DockingFrames/blob/master/docking-frames-core/src/bibliothek/gui/DockUI.java

I guess you are using an older version of the library - because the version check already failed for Java 9, where the version number got a new format. You can get the newest version (1.1.3.p1) here: https://docking-frames.org/download.html

...

In case you are wondering: the last release was 2018. Since Swing is mostly dead, no updates for DockingFrames were required either.

Please note: if you got your version from maven: I do (no longer) actively put any effort in supporting maven - just download the code from github or the compiled JAR files from my website.

enwi commented 3 years ago

I think maven is the culprit here. The error occurred at work on a newer machine, but the code base of our software is quite old. I thought the code was still maintained for maven, so I will just get the "newer" 😆 JAR.