Skip to content

Commit

Permalink
Fix NPE when reading empty YAML or JSON file
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienlauer committed Sep 12, 2019
1 parent 9443bad commit 70c6df4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Version 3.1.5 (2019-09-12)

* [fix] Fix NullPointerException when a YAML or JSON file read by the Jackson provider is empty.

# Version 3.1.4 (2018-12-18)

* [fix] Fix macro and function evaluation in properties mapping/unmapping.
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/org/seedstack/coffig/provider/JacksonProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package org.seedstack.coffig.provider;

import com.fasterxml.jackson.databind.JsonNode;
Expand Down Expand Up @@ -107,11 +108,13 @@ private MapNode buildTreeFromSource(URL url) {

private MapNode buildTreeFromFields(JsonNode node) {
List<NamedNode> namedNodes = new ArrayList<>();
node.fields().forEachRemaining(entry -> {
String name = entry.getKey();
TreeNode treeNode = buildTreeFromField(entry.getValue());
namedNodes.add(new NamedNode(name, treeNode));
});
if (node != null) {
node.fields().forEachRemaining(entry -> {
String name = entry.getKey();
TreeNode treeNode = buildTreeFromField(entry.getValue());
namedNodes.add(new NamedNode(name, treeNode));
});
}
return new MapNode(namedNodes.toArray(new NamedNode[0]));
}

Expand Down

0 comments on commit 70c6df4

Please sign in to comment.