Mojira Archive
MC-33041

Dedicated server logs "java.io.IOException: The handle is invalid" on startup

Moderator Note

This error should not have any side effects and can be ignored (see section "Code analysis" for an explanation).
When starting the server from the command line no error is logged, for example:

java -Xmx1024M -Xms1024M -jar server.jar

The bug

When the dedicated server is started by double clicking the .jar file it logs the following error on startup:

1.13
[09:23:17 ERROR]: Exception handling console input
java.io.IOException: The handle is invalid
	at java.io.FileInputStream.readBytes(Native Method) ~[?:1.8.0_172]
	at java.io.FileInputStream.read(Unknown Source) ~[?:1.8.0_172]
	at java.io.BufferedInputStream.read1(Unknown Source) ~[?:1.8.0_172]
	at java.io.BufferedInputStream.read(Unknown Source) ~[?:1.8.0_172]
	at sun.nio.cs.StreamDecoder.readBytes(Unknown Source) ~[?:1.8.0_172]
	at sun.nio.cs.StreamDecoder.implRead(Unknown Source) ~[?:1.8.0_172]
	at sun.nio.cs.StreamDecoder.read(Unknown Source) ~[?:1.8.0_172]
	at java.io.InputStreamReader.read(Unknown Source) ~[?:1.8.0_172]
	at java.io.BufferedReader.fill(Unknown Source) ~[?:1.8.0_172]
	at java.io.BufferedReader.readLine(Unknown Source) ~[?:1.8.0_172]
	at java.io.BufferedReader.readLine(Unknown Source) ~[?:1.8.0_172]
	at sn$2.run(SourceFile:107) [server.jar:?]

Code analysis

It seems that the reason for this is that the server can process commands provided from the command prompt (System.in) and independently from the JTextField. In case you do not start the server using the command prompt it still tries to read the input from it which is not possible. It appears that there is no way to prevent this because apparently System.in is not null by default and you cannot test if the readers can read without calling the reading methods and catching exceptions (which is the way it currently behaves).

As suggested in this StackOverflow answer the method InputStream.available() could be used at the start to detect if System.in is usable. If the .jar is not started from command line, then this method throws the exception as well. In this case a warning or an info message could be logged (including the exception?) and only the GUI input could be used.