NullPointer checking when adding class to graph