あざらしとペンギンの問題

主に漫画、数値計算、幾何計算、TCS、一鰭旅、水族館、鰭脚類のことを書きます。

How to avoid NumberFormatException thrown by scala and sbt shells

This article was written on July 5, 2017 (UTC). The matter may be out of date.

I am an archlinux user. One day I opened the sbt shell, I abruptly saw an error message and the annoying stack trace beginning with

java.lang.NumberFormatException: For input string: "0x100"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:580)
    at java.lang.Integer.valueOf(Integer.java:766)
    at jline.internal.InfoCmp.parseInfoCmp(InfoCmp.java:59)
    at jline.UnixTerminal.parseInfoCmp(UnixTerminal.java:233)
    at jline.UnixTerminal.<init>(UnixTerminal.java:64)
    at jline.UnixTerminal.<init>(UnixTerminal.java:49)
    ...

The only thing I understood was that jline passed "0x100" to java.lang.Integer.parseInt and it was rejected as a wrong format.

I googled about the case and figure out how to solve it. The trouble is owing to ncurses's update on May 6, and affects programs depending on jline2.

github.com/jline/jline2/issues/281

At present this issue is settled in the latest version of jline2, after one of the contributors received the report. But an old one is still used in the latest packages of scala and sbt kept in the archlinux repository.

A simple way to avoid the exception is to replace jline2's jar file on your own. I show a how-to below:

  1. Download the latest version of jline2 from github.com/jline/jline2 and build it.
  2. Replace jline2.jar in your scala's lib directory (may be /usr/share/scala/lib) to jline2/target/jline-2.xx.xx-SNAPSHOT.jar
  3. Similarly, replace jline2.jar in your sbt's lib directory (may be under $HOME/.sbt/) to jline2/target/jline-2.xx.xx-SNAPSHOT.jar

I'll be happy if this article helps your troubleshooting.

azapen6