r/java • • Mar 22 '22

Java 18 released!

https://mail.openjdk.java.net/pipermail/jdk-dev/2022-March/006458.html
396 Upvotes

133 comments sorted by

View all comments

Show parent comments

57

u/IntelHDGraphics Mar 22 '22

UTF-8 by default

Oh, this is nice

33

u/dpash Mar 22 '22

It also has a potential to be a breaking change for some users. You can use -Dfile.encoding=COMPAT to return to the previous behaviour.

It is more likely to affect Windows users as Linux and OSX are more likely to use UTF-8 by default.

5

u/s888marks Mar 22 '22

True. But the problem can still occur on Linux, where certain configurations don't necessarily use UTF-8. This was reported here a few years ago; the poster even wrote a blog describing the problem (but didn't fully understand the solution).

https://www.reddit.com/r/java/comments/6jopas/character_encodings_an_unfortunate_experience/

The original article is no longer at that location, but can be found here:

https://web.archive.org/web/20190815062506/https://www.metricly.com/character-encodings/

You can piece together what happened by reading the original article and comments in the reddit thread. Briefly, the poster's production system was Linux configured in such a way that the JDK chose ASCII as the default charset. When a non-ASCII character was introduced, round-tripping between ASCII and UTF-8 resulted in a proliferation of U+FFFD REPLACEMENT CHARACTER.

Since the poster's shop assumed everything was UTF-8, JEP 400 would have avoided this problem entirely.

2

u/dpash Mar 22 '22

Sure. I was careful to say "more likely" because I know Linux doesn't always use UTF-8.

2

u/s888marks Mar 22 '22

Fair enough. I think the thing is that Linux usually uses UTF-8 often enough that it's pretty easy assume that it always uses UTF-8, and that assumption is almost always correct. Then in those rare circumstances where it doesn't, hijinks ensue.

2

u/Nymeriea Mar 23 '22

On windows, the encoding depends on the system language