Every node in binary tree = sum of subtree
This part of your code could probably be simplified


if (node.getLeft() != null &amp;&amp; node.getRight() != null)
{
    if ((Integer) node.getData() != sum)
    {
        return false;
    }
}
else
    return true;



First off, don't do an else statement without curly braces when the corresponding if statement has curly braces, it doesn't follow expected coding practices.

Then you should return early

if (node.getLeft() == null || node.getRight() == null) {
    return true;
} else if ((Integer) node.getData() != sum) {
    return false;
}




As your code is written in the original post it will never hit this statement


return isValid(node.getLeft()) &amp;&amp; isValid(node.getRight());



and will always return true, if (node.getLeft() == null || node.getRight() == null)