Proposal for the use of Optional for NPE prone places
kristofbolyai opened this issue ยท 3 comments
As we have seen, there are managers/models that are used a lot more often than others. Since we don't use Nullable annotations, should we introduce Optionals in Managers? This would help with random NPEs throughout the codebase. A really nice example for this is CharacterManager's CharacterInfo, which can be null for various reasons, like bad parsing or updates. I think the use of Optional would force the developers to think about the "null state" of the manager fields they depend on.
That might be a good idea, yes. Another approach, at least for this example, is that we never return null for CharacterInfo, but we can get things like the empty string for name, 0 for level, None
or similar for values like ClassType, etc.
To put it differently: I agree that we need to think about invalid states. I'm not just sure there is a "one size, fits all" solution, but that it might be different between different cases. But we could state as a rule that Managers are not allowed to return null.