Handle expected EOF after closing in a different thread

This commit is contained in:
Jeremy Lakeman
2017-06-20 16:31:20 +09:30
parent 9cb561229a
commit ef2430fd58

View File

@ -18,6 +18,7 @@ public abstract class AbstractJsonList<T, E extends Exception> {
protected final JSONTableScanner table; protected final JSONTableScanner table;
protected HttpURLConnection httpConnection; protected HttpURLConnection httpConnection;
protected JSONTokeniser json; protected JSONTokeniser json;
protected boolean closed = false;
protected long rowCount = 0; protected long rowCount = 0;
protected AbstractJsonList(ServalDHttpConnectionFactory httpConnector, JSONTableScanner table){ protected AbstractJsonList(ServalDHttpConnectionFactory httpConnector, JSONTableScanner table){
@ -88,6 +89,8 @@ public abstract class AbstractJsonList<T, E extends Exception> {
json.consume(JSONTokeniser.Token.EOF); json.consume(JSONTokeniser.Token.EOF);
return null; return null;
} }
if (closed && tok == JSONTokeniser.Token.EOF)
return null;
if (rowCount != 0) if (rowCount != 0)
JSONTokeniser.match(tok, JSONTokeniser.Token.COMMA); JSONTokeniser.match(tok, JSONTokeniser.Token.COMMA);
else else
@ -110,10 +113,11 @@ public abstract class AbstractJsonList<T, E extends Exception> {
public void close() throws IOException public void close() throws IOException
{ {
if (closed)
return;
closed = true;
httpConnection = null; httpConnection = null;
if (json != null) { if (json != null)
json.close(); json.close();
json = null;
}
} }
} }