Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid NullPointerException when customChange has no "class" attribute #1648

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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