RFR: 8354266: Fix non-UTF-8 text encoding
Magnus Ihse Bursie
ihse at openjdk.org
Fri Apr 11 10:27:40 UTC 2025
On Fri, 11 Apr 2025 03:35:11 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:
>> I have checked the entire code base for incorrect encodings, but luckily enough these were the only remaining problems I found.
>>
>> BOM (byte-order mark) is a method used for distinguishing big and little endian UTF-16 encodings. There is a special UTF-8 BOM, but it is discouraged. In the words of the Unicode Consortium: "Use of a BOM is neither required nor recommended for UTF-8". We have UTF-8 BOMs in a handful of files. These should be removed.
>>
>> Methodology used:
>>
>> I have run four different tools for using different heuristics for determining the encoding of a file:
>> * chardetect (the original, slow-as-molasses Perl program, which also had the worst performing heuristics of all; I'll rate it 1/5)
>> * uchardet (a modern version by freedesktop, used by e.g. Firefox)
>> * enca (targeted towards obscure code pages)
>> * libmagic / `file --mime-encoding`
>>
>> They all agreed on pure ASCII files (which is easy to check), and these I just ignored/accepted as good. The handling of pure binary files differed between the tools; most detected them as binary but some suggested arcane encodings for specific (often small) binary files. To keep my sanity, I decided that files ending in any of these extensions were binary, and I did not check them further:
>> * `gif|png|ico|jpg|icns|tiff|wav|woff|woff2|jar|ttf|bmp|class|crt|jks|keystore|ks|db`
>>
>> From the remaining list of non-ascii, non-known-binary files I selected two overlapping and exhaustive subsets:
>> * All files where at least one tool claimed it to be UTF-8
>> * All files where at least one tool claimed it to be *not* UTF-8
>>
>> For the first subset, I checked every non-ASCII character (using `C_ALL=C ggrep -H --color='auto' -P -n "[^\x00-\x7F]" $(cat names-of-files-to-check.txt)`, and visually examining the results). At this stage, I found several files where unicode were unnecessarily used instead of pure ASCII, and I treated those files separately. Other from that, my inspection revealed no obvious encoding errors. This list comprised of about 2000 files, so I did not spend too much time on each file. The assumption, after all, was that these files are okay.
>>
>> For the second subset, I checked every non-ASCII character (using the same method). This list was about 300+ files. Most of them were okay far as I can tell; I can confirm encodings for European languages 100%, but JCK encodings could theoretically be wrong; they looked sane but I cannot read and confirm fully. Several were in fact pure...
>
> src/demo/share/java2d/J2DBench/resources/textdata/arabic.ut8.txt line 11:
>
>> 9: تخصص اÙØ´Ùرة اÙÙ
ÙØدة "ÙÙÙÙÙÙد" رÙÙ
ا ÙØÙدا ÙÙÙ Ù
Øر٠Ù٠جÙ
Ùع اÙÙغات اÙعاÙÙ
ÙØ©Ø ÙØ°Ù٠بغض اÙÙظر ع٠ÙÙع اÙØاسÙب أ٠اÙبراÙ
ج اÙÙ
ستخدÙ
Ø©. ÙÙد تÙÙ
تبÙÙ Ù
ÙاصÙØ© "ÙÙÙÙÙÙد" Ù
ÙÙÙ ÙبÙÙ Ùادة اÙصاÙعÙÙ ÙØ£ÙظÙ
Ø© اÙØÙاسÙب ÙÙ٠اÙعاÙÙ
Ø Ù
ث٠شرÙات Ø¢Ù.بÙ.Ø¥Ù
. (IBM)Ø Ø£Ø¨ÙÙ (APPLE)Ø ÙÙÙÙÙÙÙÙÙت بÙاÙÙرد (Hewlett-Packard) Ø Ù
اÙÙرÙسÙÙت (Microsoft)Ø Ø£ÙراÙÙÙÙ (Oracle) Ø ØµÙ (Sun) ÙغÙرÙا. ÙÙ
ا أ٠اÙÙ
ÙاصÙات ÙاÙÙ
ÙاÙÙس اÙØدÙثة (Ù
Ø«Ù Ùغة اÙبرÙ
جة "جاÙا" "JAVA" ÙÙغة "Ø¥Ùس Ø¥Ù
Ø¥Ù" "XML" اÙت٠تستخدÙ
ÙبرÙ
جة اÙاÙترÙÙت) تتطÙب استخداÙ
"ÙÙÙÙÙÙد". عÙاÙØ© عÙÙ Ø°ÙÙ Ø ÙØ¥Ù "ÙÙÙÙÙÙد" Ù٠اÙØ·ÙرÙÙÙÙØ© اÙرسÙÙ
ÙØ© ÙتطبÙ٠اÙÙ
ÙÙÙاس اÙÙعÙاÙÙÙ
٠إÙز٠١٠Ù
¦Ù¤Ù¦ (ISO 10646) .
>> 10:
>> 11: إ٠بزÙغ Ù
ÙاصÙØ© "ÙÙÙÙÙÙد" ÙتÙÙÙÙر اÙØ£ÙظÙ
Ø© اÙت٠تستخدÙ
Ù ÙتدعÙ
ÙØ Ùعتبر Ù
٠أÙÙ
اÙاختراعات اÙØدÙثة Ù٠عÙÙÙ
Ø© اÙبرÙ
جÙات ÙجÙ
Ùع اÙÙغات Ù٠اÙعاÙÙ
. Ùإ٠استخداÙ
"ÙÙÙÙÙÙد" Ù٠عاÙÙ
اÙاÙترÙÙت سÙؤد٠إÙ٠تÙÙÙر ÙبÙر Ù
ÙارÙØ© Ù
ع استخداÙ
اÙÙ
جÙ
Ùعات اÙتÙÙÙدÙØ© ÙÙÙ
Øار٠اÙÙ
Ø´Ùرة. ÙÙ
ا أ٠استخداÙ
"ÙÙÙÙÙÙد" سÙÙÙ
ÙÙÙ٠اÙÙ
برÙ
ج Ù
Ù Ùتابة اÙبرÙاÙ
ج Ù
رة ÙاØØ¯Ø©Ø ÙاستخداÙ
٠عÙ٠أ٠ÙÙع Ù
٠اÙأجÙزة أ٠اÙØ£ÙظÙ
Ø©Ø ÙÙØ£Ù Ùغة أ٠دÙÙØ© Ù٠اÙعاÙÙ
Ø£ÙÙÙ
ا ÙاÙØªØ Ø¯Ù٠اÙØاجة Ùإعادة اÙبرÙ
جة أ٠إجراء أ٠تعدÙÙ. ÙأخÙØ±Ø§Ø Ùإ٠استخداÙ
"ÙÙÙÙÙÙد" سÙÙ
Ù٠اÙبÙاÙات Ù
٠اÙاÙتÙا٠عبر اÙØ£ÙظÙ
Ø© ÙاÙأجÙزة اÙÙ
ختÙÙØ© دÙ٠أ
٠خطÙرة ÙتØرÙÙÙØ§Ø Ù
ÙÙ
ا تعددت اÙشرÙات اÙصاÙعة ÙÙØ£ÙظÙ
Ø© ÙاÙÙØºØ§ØªØ ÙاÙدÙ٠اÙت٠تÙ
ر Ù
Ù Ø®ÙاÙÙا Ùذ٠اÙبÙاÙات.
>
> Looks like most of the changes in java2d/* are related to spaces at the end of the line?
No, that are just incidental changes (see https://github.com/openjdk/jdk/pull/24566#issuecomment-2795201480). The actual change for the java2d files is the removal of the initial UTF-8 BOM. Github has a hard time showing this though, since the BOM is not visible.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24566#discussion_r2039258980
More information about the hotspot-dev
mailing list