scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

scala ignores system file encoding (and other system properties) #1581

Open scabug opened 15 years ago

scabug commented 15 years ago

It was reported on IRC that some simple scala source to read and output a file choked a few characters in. We discovered that although java and other languages correctly determine his locale and that ISO-8859 need be assumed, scala does not, and here is why:

  private val propFilename = "/library.properties"
  [...]
  val encodingString: String = {
    val defaultString = "UTF8" //"ISO-8859-1"
    props.getProperty("file.encoding", defaultString)
  }

Both the compiler and library default properties are seeded from files in the jars (compiler.properties and library.properties) which contain only copyright and version information. Thus the above code is not using UTF8 only when file.encoding is not set in the system properties; it is using UTF8 always.

This is true of some other properties as well, e.g.

  val shellPromptString: String = {
    val defaultString = "\nscala> "
    props.getProperty("shell.prompt", defaultString)    
  }

Conversely, settings which do use system defaults are checking the system properties object directly.

  val scalaHome: String =
    System.getProperty("scala.home")

As a note of caution, fixing this would change the default scala encoding on most platforms. On the mac the default file.encoding is MacRoman, and on windows I think it varies. Some additional logic to smooth all that out is probably appropriate, but what surely ought to be a bug is ignoring someone's intentionally set system settings and consequently failing to read their data, when java does the right thing.

scabug commented 15 years ago

Imported From: https://issues.scala-lang.org/browse/SI-1581?orig=1 Reporter: @paulp

scabug commented 15 years ago

@odersky said: I am not sure what the status of this one is, and who's tracking it.

scabug commented 15 years ago

@paulp said: Replying to [comment:7 odersky]:

I am not sure what the status of this one is, and who's tracking it.

I'm still under the belief this is for me to figure out and document (mine by default, but nonetheless.) I just haven't been all that excited to come back to it, and I've also been holding out hope that the decision to inflict MacRoman on another generation of OSX scala users can be unmade.

scabug commented 14 years ago

@paulp said: Punting downstream.