+3  A: 

In front of each "return -1" insert a

ex.printStackTrace();

This will most likely tell you what you need to know.

Thorbjørn Ravn Andersen
Those errors aren't being called. The -1 comes from a different snippet of code that I didn't include. Basically that error is produced because the new ArrayList is empty, meaning that when I opened a URL stream it had nothing in it.
Uri
Have you considered using _different_ error codes so they actually tell you something useful?
Thorbjørn Ravn Andersen
@Uri Then run it with `ex.printStackTrace()`? It will tell you more about what exactly went wrong, instead of guessing and clairvoyance. ;-)
Santa
@Santa there is no Exception object where the "error" is being thrown. I am simply calling an if statement. If list is empty return -1.
Uri
@Uri So these lines is the originator, then:` if (index.isEmpty()) { return -1; }`Nothing was ever put into `index`, possibly because your while loop never got to execute (because, like weiresr said, the first call to `in.ready()` returned `false`).
Santa
+2  A: 

So what's your behaviour on your "problem" server with the full example code when running it three times in a row? Does it always produce the same result if you run it a couple of times?

Could it be that

in.ready()

simply returns false the first time it's checked in the loop, because your target server simply doesn't send the response quickly enough?

weiresr
This helped a lot. I added a while loop that keeps trying to connect until the stream is ready. Although this doesn't seem like the most efficient way to do it. Any suggestions?
Uri
I would research if the `in.ready()` call is necessary at all. It seems that the underlying input stream of the connection object can block on read by default (with (optional?) timeout).
Santa