You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
15 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>AnnotatedNullability (infer.Nullsafe.AnnotatedNullability)</title><link rel="stylesheet" href="../../../odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 1.5.0"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div class="content"><header><nav><a href="../index.html">Up</a> <a href="../../index.html">infer</a> &#x00BB; <a href="../index.html">Nullsafe</a> &#x00BB; AnnotatedNullability</nav><h1>Module <code>Nullsafe.AnnotatedNullability</code></h1></header><aside><p>Nullability of a type in Java program (e.g. in a function or field declaration). It might come from explicit annotations (or lack of annotation), or from other sources, including conventions about defaults, models, or the mode nullsafe runs in. NOTE: This is complementary to <a href="../InferredNullability/index.html#type-t"><code>InferredNullability.t</code></a>. <a href="../InferredNullability/index.html"><code>InferredNullability</code></a> contains info about _actual_ nullability (what did nullsafe infer according to its flow-sensitive rules.). In contrast, AnnotatedNullability represents _formal_ type as it appears in the program code. NOTE: Nullsafe disregards user-provided annotations for local types, so annotated nullability applies only for types declared at methods and field level.</p></aside><dl><dt class="spec type" id="type-t"><a href="#type-t" class="anchor"></a><code><span class="keyword">type</span> t</code><code> = </code><table class="variant"><tr id="type-t.Nullable" class="anchored"><td class="def constructor"><a href="#type-t.Nullable" class="anchor"></a><code>| </code><code><span class="constructor">Nullable</span> <span class="keyword">of</span> <a href="index.html#type-nullable_origin">nullable_origin</a></code></td></tr><tr id="type-t.ThirdPartyNonnull" class="anchored"><td class="def constructor"><a href="#type-t.ThirdPartyNonnull" class="anchor"></a><code>| </code><code><span class="constructor">ThirdPartyNonnull</span></code></td></tr><tr id="type-t.UncheckedNonnull" class="anchored"><td class="def constructor"><a href="#type-t.UncheckedNonnull" class="anchor"></a><code>| </code><code><span class="constructor">UncheckedNonnull</span> <span class="keyword">of</span> <a href="index.html#type-unchecked_nonnull_origin">unchecked_nonnull_origin</a></code></td></tr><tr id="type-t.LocallyTrustedNonnull" class="anchored"><td class="def constructor"><a href="#type-t.LocallyTrustedNonnull" class="anchor"></a><code>| </code><code><span class="constructor">LocallyTrustedNonnull</span></code></td></tr><tr id="type-t.LocallyCheckedNonnull" class="anchored"><td class="def constructor"><a href="#type-t.LocallyCheckedNonnull" class="anchor"></a><code>| </code><code><span class="constructor">LocallyCheckedNonnull</span></code></td></tr><tr id="type-t.StrictNonnull" class="anchored"><td class="def constructor"><a href="#type-t.StrictNonnull" class="anchor"></a><code>| </code><code><span class="constructor">StrictNonnull</span> <span class="keyword">of</span> <a href="index.html#type-strict_nonnull_origin">strict_nonnull_origin</a></code></td></tr></table></dt><dd><p>See <a href="../Nullability/index.html#type-t"><code>Nullability.t</code></a> for explanation</p></dd></dl><dl><dt class="spec type" id="type-nullable_origin"><a href="#type-nullable_origin" class="anchor"></a><code><span class="keyword">and</span> nullable_origin</code><code> = </code><table class="variant"><tr id="type-nullable_origin.AnnotatedNullable" class="anchored"><td class="def constructor"><a href="#type-nullable_origin.AnnotatedNullable" class="anchor"></a><code>| </code><code><span class="constructor">AnnotatedNullable</span></code></td><td class="doc"><p>The type is expicitly annotated with <code>@Nullable</code> in the code</p></td></tr><tr id="type-nullable_origin.AnnotatedPropagatesNullable" class="anchored"><td class="def constructor"><a href="#type-nullable_origin.AnnotatedPropagatesNullable" class="anchor"></a><code>| </code><code><span class="constructor">AnnotatedPropagatesNullable</span></code></td><td class="doc"><p>If a function param is annotated as <code>@PropagatesNullable</code>, this param is automatically nullable</p></td></tr><tr id="type-nullable_origin.HasPropagatesNullableInParam" class="anchored"><td class="def constructor"><a href="#type-nullable_origin.HasPropagatesNullableInParam" class="anchor"></a><code>| </code><code><span class="constructor">HasPropagatesNullableInParam</span></code></td><td class="doc"><p>If a method has at least one param marked as <code>@PropagatesNullable</code>, return value is automatically nullable</p></td></tr><tr id="type-nullable_origin.ModelledNullable" class="anchored"><td class="def constructor"><a href="#type-nullable_origin.ModelledNullable" class="anchor"></a><code>| </code><code><span class="constructor">ModelledNullable</span></code></td><td class="doc"><p>nullsafe knows it is nullable via its internal models</p></td></tr></table></dt><dt class="spec type" id="type-unchecked_nonnull_origin"><a href="#type-unchecked_nonnull_origin" class="anchor"></a><code><span class="keyword">and</span> unchecked_nonnull_origin</code><code> = </code><table class="variant"><tr id="type-unchecked_nonnull_origin.AnnotatedNonnull" class="anchored"><td class="def constructor"><a href="#type-unchecked_nonnull_origin.AnnotatedNonnull" class="anchor"></a><code>| </code><code><span class="constructor">AnnotatedNonnull</span></code></td><td class="doc"><p>The type is explicitly annotated as non nullable via one of nonnull annotations Nullsafe recognizes</p></td></tr><tr id="type-unchecked_nonnull_origin.ImplicitlyNonnull" class="anchored"><td class="def constructor"><a href="#type-unchecked_nonnull_origin.ImplicitlyNonnull" class="anchor"></a><code>| </code><code><span class="constructor">ImplicitlyNonnull</span></code></td><td class="doc"><p>Infer was run in mode where all not annotated (non local) types are treated as non nullable</p></td></tr></table></dt><dt class="spec type" id="type-strict_nonnull_origin"><a href="#type-strict_nonnull_origin" class="anchor"></a><code><span class="keyword">and</span> strict_nonnull_origin</code><code> = </code><table class="variant"><tr id="type-strict_nonnull_origin.ExplicitNonnullThirdParty" class="anchored"><td class="def constructor"><a href="#type-strict_nonnull_origin.ExplicitNonnullThirdParty" class="anchor"></a><code>| </code><code><span class="constructor">ExplicitNonnullThirdParty</span></code></td><td class="doc"><p>Third party annotated as <code>@Nonnull</code> is considered strict. This is a controversial choice and might be an unsoundness issue. The reason is practical. The best we can do for third party is to register it in third party signature repository. Though this typically requires human review, in practice errors are inevitable. On the other hand, if the library owner explicitly annotated a function as nonnull, we assume this was made for reason. In practice, requiring such methods to be registered in third party folder, will introduce user friction but will not significantly increase safety. So our approach here is optimistic. If some particular method or library is known to contain wrong <code>@Nonnull</code> annotations, third party repository is a way to override this.</p></td></tr><tr id="type-strict_nonnull_origin.ModelledNonnull" class="anchored"><td class="def constructor"><a href="#type-strict_nonnull_origin.ModelledNonnull" class="anchor"></a><code>| </code><code><span class="constructor">ModelledNonnull</span></code></td><td class="doc"><p>nullsafe knows it is non-nullable via its internal models</p></td></tr><tr id="type-strict_nonnull_origin.StrictMode" class="anchored"><td class="def constructor"><a href="#type-strict_nonnull_origin.StrictMode" class="anchor"></a><code>| </code><code><span class="constructor">StrictMode</span></code></td><td class="doc"><p>under strict mode we consider non-null declarations to be trusted</p></td></tr><tr id="type-strict_nonnull_origin.PrimitiveType" class="anchored"><td class="def constructor"><a href="#type-strict_nonnull_origin.PrimitiveType" class="anchor"></a><code>| </code><code><span class="constructor">PrimitiveType</span></code></td><td class="doc"><p>Primitive types are non-nullable by language design</p></td></tr><tr id="type-strict_nonnull_origin.EnumValue" class="anchored"><td class="def constructor"><a href="#type-strict_nonnull_origin.EnumValue" class="anchor"></a><code>| </code><code><span class="constructor">EnumValue</span></code></td><td class="doc"><p>Java enum value are statically initialized with non-nulls according to language semantics</p></td></tr><tr id="type-strict_nonnull_origin.SyntheticField" class="anchored"><td class="def constructor"><a href="#type-strict_nonnull_origin.SyntheticField" class="anchor"></a><code>| </code><code><span class="constructor">SyntheticField</span></code></td><td class="doc"><p>Fake field that is not part of user codebase, but rather artifact of codegen/annotation processor</p></td></tr></table></dt></dl><div><div class="spec include"><div class="doc"><dl><dt class="spec value" id="val-compare"><a href="#val-compare" class="anchor"></a><code><span class="keyword">val</span> compare : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> int</code></dt><dt class="spec value" id="val-compare_nullable_origin"><a href="#val-compare_nullable_origin" class="anchor"></a><code><span class="keyword">val</span> compare_nullable_origin : <a href="index.html#type-nullable_origin">nullable_origin</a> <span>&#45;&gt;</span> <a href="index.html#type-nullable_origin">nullable_origin</a> <span>&#45;&gt;</span> int</code></dt><dt class="spec value" id="val-compare_unchecked_nonnull_origin"><a href="#val-compare_unchecked_nonnull_origin" class="anchor"></a><code><span class="keyword">val</span> compare_unchecked_nonnull_origin : <a href="index.html#type-unchecked_nonnull_origin">unchecked_nonnull_origin</a> <span>&#45;&gt;</span> <a href="index.html#type-unchecked_nonnull_origin">unchecked_nonnull_origin</a> <span>&#45;&gt;</span> int</code></dt><dt class="spec value" id="val-compare_strict_nonnull_origin"><a href="#val-compare_strict_nonnull_origin" class="anchor"></a><code><span class="keyword">val</span> compare_strict_nonnull_origin : <a href="index.html#type-strict_nonnull_origin">strict_nonnull_origin</a> <span>&#45;&gt;</span> <a href="index.html#type-strict_nonnull_origin">strict_nonnull_origin</a> <span>&#45;&gt;</span> int</code></dt><dt class="spec value" id="val-compare"><a href="#val-compare" class="anchor"></a><code><span class="keyword">val</span> compare : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> int</code></dt><dt class="spec value" id="val-compare_nullable_origin"><a href="#val-compare_nullable_origin" class="anchor"></a><code><span class="keyword">val</span> compare_nullable_origin : <a href="index.html#type-nullable_origin">nullable_origin</a> <span>&#45;&gt;</span> <a href="index.html#type-nullable_origin">nullable_origin</a> <span>&#45;&gt;</span> int</code></dt><dt class="spec value" id="val-compare_unchecked_nonnull_origin"><a href="#val-compare_unchecked_nonnull_origin" class="anchor"></a><code><span class="keyword">val</span> compare_unchecked_nonnull_origin : <a href="index.html#type-unchecked_nonnull_origin">unchecked_nonnull_origin</a> <span>&#45;&gt;</span> <a href="index.html#type-unchecked_nonnull_origin">unchecked_nonnull_origin</a> <span>&#45;&gt;</span> int</code></dt><dt class="spec value" id="val-compare_strict_nonnull_origin"><a href="#val-compare_strict_nonnull_origin" class="anchor"></a><code><span class="keyword">val</span> compare_strict_nonnull_origin : <a href="index.html#type-strict_nonnull_origin">strict_nonnull_origin</a> <span>&#45;&gt;</span> <a href="index.html#type-strict_nonnull_origin">strict_nonnull_origin</a> <span>&#45;&gt;</span> int</code></dt><dt class="spec value" id="val-compare"><a href="#val-compare" class="anchor"></a><code><span class="keyword">val</span> compare : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> int</code></dt><dt class="spec value" id="val-compare_nullable_origin"><a href="#val-compare_nullable_origin" class="anchor"></a><code><span class="keyword">val</span> compare_nullable_origin : <a href="index.html#type-nullable_origin">nullable_origin</a> <span>&#45;&gt;</span> <a href="index.html#type-nullable_origin">nullable_origin</a> <span>&#45;&gt;</span> int</code></dt><dt class="spec value" id="val-compare_unchecked_nonnull_origin"><a href="#val-compare_unchecked_nonnull_origin" class="anchor"></a><code><span class="keyword">val</span> compare_unchecked_nonnull_origin : <a href="index.html#type-unchecked_nonnull_origin">unchecked_nonnull_origin</a> <span>&#45;&gt;</span> <a href="index.html#type-unchecked_nonnull_origin">unchecked_nonnull_origin</a> <span>&#45;&gt;</span> int</code></dt><dt class="spec value" id="val-compare_strict_nonnull_origin"><a href="#val-compare_strict_nonnull_origin" class="anchor"></a><code><span class="keyword">val</span> compare_strict_nonnull_origin : <a href="index.html#type-strict_nonnull_origin">strict_nonnull_origin</a> <span>&#45;&gt;</span> <a href="index.html#type-strict_nonnull_origin">strict_nonnull_origin</a> <span>&#45;&gt;</span> int</code></dt></dl></div></div></div><dl><dt class="spec value" id="val-get_nullability"><a href="#val-get_nullability" class="anchor"></a><code><span class="keyword">val</span> get_nullability : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <a href="../Nullability/index.html#type-t">Nullability.t</a></code></dt><dt class="spec value" id="val-of_type_and_annotation"><a href="#val-of_type_and_annotation" class="anchor"></a><code><span class="keyword">val</span> of_type_and_annotation : <span>is_callee_in_trust_list:bool</span> <span>&#45;&gt;</span> <span>nullsafe_mode:<a href="../NullsafeMode/index.html#type-t">NullsafeMode.t</a></span> <span>&#45;&gt;</span> <span>is_third_party:bool</span> <span>&#45;&gt;</span> <a href="../../IR/Typ/index.html#type-t">IR.Typ.t</a> <span>&#45;&gt;</span> <a href="../../IR/Annot/Item/index.html#type-t">IR.Annot.Item.t</a> <span>&#45;&gt;</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Given the type and its annotations, returns its nullability. NOTE: it does not take into account models etc., so this is intended to be used as a helper function for more high-level annotation processing. <code>is_callee_in_trust_list</code> defines whether the callee class is in the caller's explicitly provided trust list and therefore whether its nullability should be refined.</p></dd></dl><dl><dt class="spec value" id="val-pp"><a href="#val-pp" class="anchor"></a><code><span class="keyword">val</span> pp : Stdlib.Format.formatter <span>&#45;&gt;</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> unit</code></dt></dl></div></body></html>