My question is similar to Printing Unicode from Scala interpreter and scala default encoding in windows shell, but goes into more detail WRT different behavior of Scala (version 2.12.2) vs. Groovy (version 2.4.7).
I have the following code snippet (which happens to be both valid Scala and Groovy code):
println("└─ ");
println("├─ ");
println(System.getProperty("file.encoding"));
When running the scala
interpreter on it the Windows terminal (all of cmd, PowerShell, Git Bash / mintty) it shows
$ scala a.scala
??
??
Cp1252
However, running the exact same code through the groovy
interpreter it shows:
$ groovy a.scala
└─
├─
Cp1252
My understanding from reading the answers to the linked questions is that the output is (solely) dependent on the value of the file.encoding
system property. If so, how can the output be different between Scala and Groovy then if the used file.encoding
is the same?
Edit: This answer seems to confirm it's an issue with the encoding used by the Scala compiler to read the source code file, which seems to default to whatever file.encoding
is set to, even if the file clearly is UTF-8 encoded. I'm still wondering why Scala is not as smart as Groovy here...
Edit 2: I can work around the issue by running
$ scala -Dfile.encoding=UTF8 a.scala
└─
├─
UTF8
but still this dos not answer the question why Groovy does get it right despite file.encoding
being set to Cp1252
.