More of a beginner's question. Please use the
code tags to preserve your indentation.
What you are doing is enforcing a precondition. If you call the precondition P and the substitution S then you have P|S ie P is a precondition for S. That would correspond to writing "must not be null" in the documentation comments. But the user might still pass null and get into trouble afterwards, which is not your fault.
Now you can be more assertive about your precondition and enforce it by upgrading it to a guard which we shall call G. You write G--->S pronounced G guards S. It means in fact that S will only run if G is true. You could write
. . . if (anId == null) id = ("new ID");
That won't work well, so you have gone up one stage in assertiveness and thrown an Exception. You are really now enforcing the guard.
Yes, throwing an Exception like that is the correct thing to do.
You should add comments to the documentation and a @throws NullPointerException tag (in the documentation comment) so the user knows what to expect.