jide-oss icon indicating copy to clipboard operation
jide-oss copied to clipboard

SystemInfo.JavaVersion can't correctly parse single Java versions like "12", "13", ..

Open hamid-nazari opened this issue 5 years ago • 4 comments

Using the latest version of JavaSE-13 whose version is "13" with no dots, I encountered a high CPU usage in my code which did not exist in JavaSE-12.0.2 or earlier.

After tracing it I found out that com.jidesoft.utils.SystemInfo.JavaVersion is not detecting Java version correctly and is reporting it as Java v1.4 ! Looking at the code was obvious why; I see that the RegEx used to parse Java version: private static Pattern SUN_JAVA_VERSION = Pattern.compile("(\\d+\\.\\d+)(\\.(\\d+))?(_([^-]+))?(.*)"); is expecting at least a version with two digits separated by a dot which is not the case any more thanks to the new Java 10 versioning scheme, now we are going to encounter versions like "13" which is what I have.

The fix is straight forward, something like this which I've applied and things are now working fine for me on JavaSE-13:

private static Pattern SUN_JAVA_VERSION = Pattern.compile("(\\d+(?:\\.\\d+)?)(\\.(\\d+))?(_([^-]+))?(.*)");

I think it would be wise to change the other safe net RegEx, too:

private static Pattern SUN_JAVA_VERSION_SIMPLE = Pattern.compile("(\\d+(?:\\.\\d+)?)(\\.(\\d+))?(.*)");

hamid-nazari avatar Sep 29 '19 20:09 hamid-nazari

👍 I can also confirm this problem.

raducoravu avatar Sep 30 '19 05:09 raducoravu

Thank you both. I just committed and pushed the change.

jidesoft avatar Sep 30 '19 16:09 jidesoft