Wynntils

Wynntils

611k Downloads

Enhance null-safety with wrapping all enum `fromString` methods in Optional

kristofbolyai opened this issue ยท 3 comments

commented

Many implementations ignore the fact that enums can return null in fromString and other parsing methods. While this is not something that breaks magically, a new wynn update could easily create multiple crashes, which could be easily handled.

commented

An alternative to wrapping in Optional (which I want to avoid if possible; the only thing worse than that is returning a null pointer that the receiver is not prepared to handle...), is to have some kind of "null" enum value. This does not work for all enums, but for many it does make good sense to have an UNDEFINED or NONE or similar value. I'd like that to be the first hand alternative, and only if it does not at all make sense, should we use Optional wrapping.

commented

I am not sure which way "litters" the code more, but it is probably equal?

commented

Yeah, maybe. I guess any one method will do, as long as we avoid null.