Skip to content

java.nio.charset.UnmappableCharacterException: Input length = 1 #134

Closed
@RadoBuransky

Description

@RadoBuransky

I have some nice Slovak characters in source code. For example:

class Class2 {
  def msg_test = println("test code ŠTEFÁNIK")
}

But then if I run Scoverage it crashes with following:

Input length = 1
java.nio.charset.UnmappableCharacterException: Input length = 1
    at java.nio.charset.CoderResult.throwException(CoderResult.java:282)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:339)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
    at java.io.InputStreamReader.read(InputStreamReader.java:184)
    at java.io.BufferedReader.read1(BufferedReader.java:210)
    at java.io.BufferedReader.read(BufferedReader.java:286)
    at java.io.Reader.read(Reader.java:140)
    at scala.io.BufferedSource.mkString(BufferedSource.scala:96)
    at scoverage.report.CodeGrid.source(CodeGrid.scala:63)
    at scoverage.report.CodeGrid.<init>(CodeGrid.scala:17)
    at scoverage.report.ScoverageHtmlWriter.filePage(ScoverageHtmlWriter.scala:78)

It is obviously related to encoding. I am able to reproduce it by explicitly setting wrong encoding in CodeGrid.scala line 63:

  private def source(mfile: MeasuredFile): String = Source.fromFile(mfile.source, "windows-1252").mkString

Current implementation uses an arbitrary default encoding which is probably not ideal. It can be different for every one of us. I would propose to hardcode UTF-8. If you like this idea, I will send a pull request soon.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions