Always return null once a json parser has closed

This commit is contained in:
Jeremy Lakeman 2018-06-26 14:32:00 +09:30
parent 2f3b8cadc4
commit 3d2eb1c260
2 changed files with 19 additions and 9 deletions

View File

@ -111,7 +111,7 @@ public class JsonParser {
if (current != ch) {
return false;
}
read();
current=0;
return true;
}
@ -122,14 +122,8 @@ public class JsonParser {
private void requireConstString(String str) throws IOException, JsonParseException{
// Check for every character, without attempting to read past the end
for(int i=0;i<str.length();i++) {
if (current == 0)
read();
char ch = str.charAt(i);
if (current != ch)
expected("'"+ch+"'");
current = 0;
}
for(int i=0;i<str.length();i++)
requireChar(str.charAt(i));
}
private void skipWhiteSpace() throws IOException {
@ -404,6 +398,8 @@ public class JsonParser {
public String readString() throws IOException, JsonParseException {
StringBuilder sb = new StringBuilder();
requireChar('"');
if (current == 0)
read();
while(current != '"'){
if (current == '\\'){
switch (read()) {

View File

@ -67,6 +67,20 @@ public abstract class HttpJsonSerialiser<T, E extends Exception> extends JsonTab
}
}
@Override
public T next() throws IOException, JsonParser.JsonParseException, E {
if (closed)
return null;
try {
return super.next();
}catch (IOException | JsonParser.JsonParseException e){
// don't throw if a close was triggered from another thread
if (closed)
return null;
throw e;
}
}
public void close() throws IOException
{
if (closed)