In Intellij IDEA 14 there is a feature called Automatic Contract inference [1].
What exactly does the inferred @Flow annotation mean?
For example for Collection's boolean addAll(Collection<? extends E> c)
the inferred contract is
boolean addAll(@NotNull @Flow Collection<? extends E> c)
.
What does @Flow
mean in this context?
Disclaimer: I haven't been able to find any massively detailed descriptions or examples of this, so most of this is speculation.
The best documentation I've found for
@Flow
so far is what one can read in the comments on the annotation itself, as one can see here.Excerpt:
In a nutshell, it's a form of metadata IntelliJ needs to do some types of code analysis on how data enters and exits a collection or similar. Not sure exactly what type of analysis is done using this, but I assume that some of IntelliJ's inspections make use of it.
I speculate that an inspection similar to the following could theoretically be made using this metadata (if it doesn't already exist):
@Flow
, data passed tovoid push(Object)
can eventually be returned fromObject pull()
pull
is dereferenced without checking fornull
, give a warning ifnull
is ever passed intopush
.Before
@Flow
was added, this presumably had to be hardcoded into IntelliJ and would thus only work for Java's standard container classes, arrays and stuff (assuming this specific type of analysis was even done before). Adding@Flow
would thus make it more flexible and also allow custom containers to be analyzed in the same way.If anyone has more solid information about
@Flow
and some real world examples of how it's used, I too would be interested in seeing it.