Community
Participate
Working Groups
From bug 383371 comment 58 > I have a idea I wanted to share while thinking of EJB-Entities: > > It is basically the empty-Constructor that is used by the framework to > construct the Entity from the Database. In that case the initialization is > done by the framework, and we do not need an initialization-check. > If you create a new Entity in your code you probably use another > constructor, with parameters to initialize the NonNull-fields. So an > initialization-check would be useful in the second case, but not in the > first case. > > I think it would make sense to annotate *Construtors* with a > @SupressWarning("initialization"). Maybe allow it on the Class itself for > all constructors. Static fields should still be checked though, since those > are usually constants. > > If you have no constructor at all (only the default one then), I don't think > it is too much work to simply add the empty constructor for the annotation > in that case. One might argue that we already have @SuppressWarnings("null") which could be applied to the constructors in question. However, this would obviously hide other relevant warnings. @SuppressWarnings("null") even for an entire class is a no-go, whereas @SuppressWarnings("initialization") on a class might be fair. BTW, I suggest to shorten the token to "initialize". Another point to consider: missing initialization of @NonNull fields is ranked as NullSpecViolation, which by default is set to "Error". This means in typical situations the new warning token would only help in conjunction with [x] Suppress optional errors with '@SuppressWarnings'. Is everybody fine with that? OK, I thinks this is an interesting proposal but we currently can't commit to it.