FindJava: Sorting of versions broken on Windows
On Windows FindJava
searches the registry for installed Java versions and tries to sort them such that more recent versions are found before older ones. However, this sorting is done alphabetically instead of numerically with a special treatment of version 9. In addition, it does not consider that some Java versions are known as major and minor versions, such that 1.5 = 5, 1.6 = 6, ...
Analysing the code in Modules/FindJava.cmake
results in the following order if all available Java versions are present:
- 8
- 7
- 6
- 5
- 21
- 20
- 19
- ...
- 10
- 1.8
- 1.7
- ...
- 1.0
- 9
Note, that there were no versions 2, 3, and 4 (instead they were known as 1.2, 1.3, and 1.4). See Wikipedia for more about Java versions.
Of these versions only the first one present is considered at all. So it may happen that an older version is used by CMake although a newer one is present.
Even worse, if the user requests an exact version, it is not found when another version more to the top of the list is present.
I've analyzed the code that came with CMake 3.19 but there were no relevant changes in the code of FindJava.cmake
until today's (2022-05-03) master version.