mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-18 12:56:29 +00:00
Always return null once a json parser has closed
This commit is contained in:
parent
2f3b8cadc4
commit
3d2eb1c260
@ -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()) {
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user