Skip to content

Commit

Permalink
Merge pull request #1648 from danielthegray/improve-missing-class-nam…
Browse files Browse the repository at this point in the history
…e-custom-change-error

Avoid NullPointerException when customChange has no "class" attribute
  • Loading branch information
nvoxland committed Feb 14, 2022
2 parents 7403ec2 + fc0771b commit c6ed3fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Expand Up @@ -291,7 +291,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 @@ -273,6 +273,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 c6ed3fe

Please sign in to comment.