Skip to content

Commit

Permalink
Avoid NullPointerException when customChange has no "class" attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
danielthegray committed May 6, 2021
1 parent 8e92ac7 commit 77ec354
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Expand Up @@ -285,7 +285,11 @@ public String getSerializedObjectNamespace() {
@Override
public void load(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException {
try {
setClass(parsedNode.getChildValue(null, "class", String.class));
String classNameValue = parsedNode.getChildValue(null, "class", String.class);
if (classNameValue == null) {
throw new ParsedNodeException("Custom change node has no 'class' attribute!");
}
setClass(classNameValue);
} catch (CustomChangeException e) {
throw new ParsedNodeException(e);
}
Expand Down
Expand Up @@ -257,6 +257,16 @@ class CustomChangeWrapperTest extends Specification {

}

def "customChange without class fails expectedly"() {
when:
def node = new ParsedNode(null, "customChange")
def change = new CustomChangeWrapper()
change.load(node, resourceSupplier.simpleResourceAccessor)

then:
thrown(ParsedNodeException.class)
}

def "load handles params in a 'params' collection"() {
when:
def node = new ParsedNode(null, "customChange")
Expand Down

0 comments on commit 77ec354

Please sign in to comment.