My question is: if this two functions have something different? I mean I know that they return something different, but is it possible that number of elements in one would be different then in the second one. I will try to explain. I implemented TreeModel for one of my class trying to make nice view on files on the PC basing on JTree. So here is the part of it:
public Object getChild(Object parent, int index) {
        File[] children = ((File) parent).listFiles();
        if(children == null || index < 0 || index >= children.length) {
            return null;
        }
        File result = new MyFile(children[index]);
        return result;
}
public int getChildCount(Object parent) {
        //---
        //String[] children = ((File)parent).list();
        File[] children = ((File)parent).listFiles();
        //---
        if(children == null) {
            return 0;
        }
        return children.length;
}
I marked interesting code. If I changed this two lines for this commented one, sometimes I get NullPointerException after loading TreeModel: jtree.setModel(treeModel);. This uncommented does not cause any trouble. I checked the docs and it says nothing unusual including returning null by both methods. What is going on here?
 
     
    