+ Start a Discussion
wsmithwsmith 

Parameterized Typing and Interfaces Throws java.lang.NullPointerException Without Stacktrace

The following code sample has been throwing an error (by testMethod, execute anonymous, etc.) since the weekend of June 9, 2012. The error is a java.lang.NullPointerException which does not produce a stacktrace.  The code has a parameterized interface which has a method to get a list of another parameterized type. Has anyone seen this error lately?

 

public without sharing class HTTree2 {

    public interface INode<TYPE_> {
        TYPE_ getValue();
        void setValue(TYPE_ value);
        INode<TYPE_> getParent();
        void setParent(INode<TYPE_> parent);
        List<INode<TYPE_>> getChildren();
    }

    public class SObjectNode implements INode<sObject> {

        private sObject value;
        private INode<sObject> parent;
        private List<INode<sObject>> children;

        public SObjectNode() {
            children = new List<INode<sObject>>();
        }

        public sObject getValue() {
            return this.value;
        }

        public void setValue(sObject value) {
            this.value = value;
        }

        public INode<sObject> getParent() {
            return this.parent;
        }

        public void setParent(INode<sObject> parent) {
            this.parent = parent;
        }

        public List<INode<sObject>> getChildren() {
            System.debug('getting children');
            return this.children;
        }

    }

    public static void test1() {
        SObjectNode n0 = new SObjectNode();
        System.debug('log0===>' + n0.getChildren().size());
        INode<sObject> n1 = new SObjectNode();
        System.debug('log1.begin===> the line below throws an error');
        // the line below throws an error
        System.debug('log1===>' + n1.getChildren());
    }

    public static testmethod void test2() {
        SObjectNode n0 = new SObjectNode();
        System.debug('log0===>' + n0.getChildren().size());
        INode<sObject> n1 = new SObjectNode();
        System.debug('log1.begin===> the line below throws an error');
        // the line below throws an error
        System.debug('log1===>' + n1.getChildren());
    }

}