Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading input from application doesn't work #882

Open
msinton opened this issue May 7, 2019 · 9 comments
Open

Reading input from application doesn't work #882

msinton opened this issue May 7, 2019 · 9 comments
Assignees
Labels
bug A defect or misbehaviour. task / run wontfix

Comments

@msinton
Copy link

msinton commented May 7, 2019

To reproduce, create a simple app such as:

object Main extends App {

  val x = readInt()
  val y = readInt()
  println(x + y)
}

When run and supply numbers (1, 2) you get the following unexpected error:

[E] Exception in thread "main" java.lang.NumberFormatException: For input string: "2"
[E] at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)

The same does not occur if running with sbt.

(p.s. Loving Bloop)

@jvican jvican added bug A defect or misbehaviour. task / run wontfix labels May 7, 2019
@jvican
Copy link
Contributor

jvican commented May 7, 2019

Caused by facebook/nailgun, ticket here. The issue is nailgun only reads line by line, and readInt only grabs four bytes of input, so it doesn't work with nailgun.

This kind of applications will work when the client is a BSP client (e.g. when Metals supports running applications, it will work). I have to close this ticket as wont fix since it needs a fix upstream. To work around this issue, I recommend replacing readInt by readLine and then parsing the string as an int.

@jvican jvican changed the title Command line apps don't work as they should Reading input from application doesn't work May 7, 2019
@jvican jvican closed this as completed May 7, 2019
@rtar
Copy link

rtar commented Nov 29, 2019

readLine() does not seem to work either. It just hangs without ever passing input to the application.

@davidpdrsn
Copy link

I'm also having issues with this. Any possible solutions?

@jvican
Copy link
Contributor

jvican commented Jan 30, 2020

This is an important issue I intend to fix soon.

In the meanwhile, you should be able to run the application via Metals in VS Code. Metals can run application reliably because it uses DAP instead of Nailgun, and DAP allows for fine-grained user input to be transmitted over the wire.

@kammoh
Copy link

kammoh commented Mar 23, 2021

Hi,
Any updates on this issue?

bloop v1.4.8, JDK 15:

$ bloop console root
error: Unexpected error forces client exit!
java.lang.NumberFormatException: For input string: "0
"
        at java.lang.Integer.parseInt(Integer.java:652)
        at java.lang.Integer.parseInt(Integer.java:770)
        at snailgun.protocol.Protocol.$anonfun$processChunkFromServer$1(Protocol.scala:193)
        at scala.util.Try$.apply(Try.scala:213)
        at snailgun.protocol.Protocol.processChunkFromServer(Protocol.scala:180)
        at snailgun.protocol.Protocol.sendCommand(Protocol.scala:108)
        at snailgun.TcpClient.run(TcpClient.scala:34)
        at bloop.bloopgun.BloopgunCli.executeCmd$1(Bloopgun.scala:268)
        at bloop.bloopgun.BloopgunCli.fireCommand(Bloopgun.scala:274)
        at bloop.bloopgun.BloopgunCli.run(Bloopgun.scala:230)
        at bloop.bloopgun.Bloopgun$.main(Bloopgun.scala:638)
        at bloop.bloopgun.Bloopgun.main(Bloopgun.scala)

@2m
Copy link
Contributor

2m commented Jul 10, 2021

I have a clean MacOS install with coursier installed via brew and bloop installed via coursier. I get this error when running bloop about:

~ ─╼ bloop about                                                                                  0
bloop v1.4.8

Using Scala v2.12.8 and Zinc v1.3.0-M4+46-edbe573e
Running on Java JDK v16.0.1 (/Library/Java/JavaVirtualMachines/adoptopenjdk-16.jdk/Contents/Home)
  -> Supports debugging user code, Java Debug Interface (JDI) is available.
Maintained by the Scala Center (Jorge Vicente Cantero, Martin Duhem)
error: Unexpected error forces client exit!
java.lang.NumberFormatException: For input string: "0
"
	at java.lang.Integer.parseInt(Integer.java:652)
	at java.lang.Integer.parseInt(Integer.java:770)
	at snailgun.protocol.Protocol.$anonfun$processChunkFromServer$1(Protocol.scala:193)
	at scala.util.Try$.apply(Try.scala:213)
	at snailgun.protocol.Protocol.processChunkFromServer(Protocol.scala:180)
	at snailgun.protocol.Protocol.sendCommand(Protocol.scala:108)
	at snailgun.TcpClient.run(TcpClient.scala:34)
	at bloop.bloopgun.BloopgunCli.executeCmd$1(Bloopgun.scala:268)
	at bloop.bloopgun.BloopgunCli.fireCommand(Bloopgun.scala:274)
	at bloop.bloopgun.BloopgunCli.run(Bloopgun.scala:230)
	at bloop.bloopgun.Bloopgun$.main(Bloopgun.scala:638)
	at bloop.bloopgun.Bloopgun.main(Bloopgun.scala)

@tgodzik
Copy link
Contributor

tgodzik commented Jul 12, 2021

This seems to be an issued with JDK 16, could you try with JDK 11? I think we fixed it in master, but will need to confirm. Anyway, I don't think this is related to current issue.

@frabbit
Copy link

frabbit commented Jul 14, 2022

I ran into the same issue, reading input from stdin is not working when running apps via bloop run. I guess it's the same reason why it's not working as expected with terminal libraries like jline for example.

@tambonbon

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A defect or misbehaviour. task / run wontfix
Projects
None yet
Development

No branches or pull requests

9 participants