Add null check to resource constructor