iron-io/iron_mq_java — Issue #4: Possible out of bounds exception
Author: coreyauger
Created: 2012-02-14 18:19:41+00:00
State: open

Following code does not deal with Array of length zero...

public Message get() throws IOException {
JSONObject jsonObj = client.get("queues/" + name + "/messages");
JSONArray array = jsonObj.getJSONArray("messages");
JSONObject jsonMsg = array.getJSONObject(0);

Message msg = new Message();
msg.setId(jsonMsg.getString("id"));
msg.setBody(jsonMsg.getString("body"));
if (jsonMsg.has("timeout")) {
msg.setTimeout(jsonMsg.getLong("timeout"));
}
return msg;
}