Does Java – IllegalStateException apply to immutable objects?
You throw an IllegalStateException if:
>The method cannot complete its work because of the value of one or more fields > which fields are final and only allocated in the constructor?
Textbook example: your class is an immutable collection < BigInteger > and your method should return the largest element, but this instance is empty
I've read Kevin bourillon ` s blog post on this topic, and I'm not sure which rule applies
Of course not Many instances of this class are not empty and the operation will succeed
Incomplete This instance is constructed with zero length, so this instance is not and will never be non empty
If the relevant parameter is implicit, this parameter can be applied This is an exception I'd love to make, but I'm afraid it may be confusing
Update: sample collection < BigInteger > has been changed from collection < integer > because the fact that there is an identity element (integer. Min_value) is distracting
Solution
I think the IllegalStateException is appropriate here If the construct is correct (that is, the "it's too late" section), the instance may be in the correct state