Are you getting a different behavior when running it from the system console vs as an external tool?
It is the same result. I also converted the script to .bsh and get the same result.
The similar code that works is converting a LinkedHashMap to a set and then testing if the set is empty.
Map xmpKeywordMap = new LinkedHashMap();
xmpKeywordMap = processXmpDir(xmpDir, xmpKeywordMap);
//Create a set out of xmpKeywordMap, then check if it is empty
Set set = xmpKeywordMap.entrySet();
if(set.isEmpty()) {
The xmpKeywordMap contains file name as a key and keywords string as value.
It is a coding mystery, to me at least, but is easily got around by not counting objects processed, just saying 'Script done'.
I'll mark this as answered, as the main reason for posting was to see if a built in option to sort keywords would be of use generally.
Postscript:
This got started as a result of
this bug post and the final script that I made, which reads in an xmp file with keywords and appends them to the matching album object (same base file name). In that script, part of of which is the 'working' code, all keywords are sorted alphabetically A-Za-z.