Skip to content

Commit

Permalink
Back-port fix for empty documents
Browse files Browse the repository at this point in the history
  • Loading branch information
A248 committed Feb 2, 2021
1 parent eb2a0ab commit 8653429
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
*/
package space.arim.dazzleconf.ext.gson;

import java.io.EOFException;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;

Expand Down Expand Up @@ -99,6 +101,9 @@ protected Map<String, Object> loadMapFromReader(Reader reader) throws IOExceptio
throw new IOException(ex);
} catch (JsonSyntaxException | MalformedJsonException ex) {
throw new ConfigFormatSyntaxException(ex);
} catch (EOFException ex) {
// JsonReader throws EOFException on empty documents
return Collections.emptyMap();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;

Expand Down Expand Up @@ -85,15 +86,18 @@ protected Charset charset() {

@Override
protected Map<String, Object> loadMapFromReader(Reader reader) throws IOException, ConfigFormatSyntaxException {
Map<String, Object> map;
try {
return yamlOptions.yamlSupplier().get().load(reader);
map = yamlOptions.yamlSupplier().get().load(reader);
} catch (YAMLException ex) {
Throwable cause = ex.getCause();
if (cause instanceof IOException) {
throw (IOException) cause;
}
throw new ConfigFormatSyntaxException(ex);
}
// SnakeYAML returns a null object for an empty document
return (map == null) ? Collections.emptyMap() : map;
}

@Override
Expand Down

0 comments on commit 8653429

Please sign in to comment.