Top Description Methods
io.opentelemetry.api.internal

pack-priv @Interface Contract

extends Annotation
Annotations
@Documented
@Retention:CLASS
@Target:METHOD, CONSTRUCTOR
Imports
java.lang.annotation.Documented, .ElementType, .Retention, .RetentionPolicy, .Target

Specifies some aspects of the method behavior depending on the arguments. Can be used by tools for advanced data flow analysis. Note that this annotation just describes how the code works and doesn't add any functionality by means of code generation.

Method contract has the following syntax:

contract ::= (clause ';')* clause
clause ::= args '->' effect
args ::= ((arg ',')* arg )?
arg ::= value-constraint
value-constraint ::= '_' | 'null' | '!null' | 'false' | 'true'
effect ::= value-constraint | 'fail' | 'this' | 'new' | 'param<N>'

The constraints denote the following:

The additional return values denote the following:

Examples:

@Contract("_, null -> null") - the method returns null if its second argument is null
@Contract("_, null -> null; _, !null -> !null") - the method returns null if its second argument is null and not-null otherwise
@Contract("true -> fail") - a typical assertFalse method which throws an exception if true is passed to it
@Contract("_ -> this") - the method always returns its qualifier (e.g. StringBuilder#append(String)). @Contract("null -> fail; _ -> param1") - the method throws an exception if the first argument is null, otherwise it returns the first argument (e.g. Objects.requireNonNull).
@Contract("!null, _ -> param1; null, !null -> param2; null, null -> fail") - the method returns the first non-null argument, or throws an exception if both arguments are null (e.g. Objects.requireNonNullElse in Java 9).

This annotation is the same provided with Jetbrains annotations and used by Nullaway for verifying nullness. We copy the annotation to avoid an external dependency.

This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.

Method Summary

Modifier and TypeMethod and Description
public String
value()

Contains the contract clauses describing causal relations between call arguments and the returned value.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public String value()

Contains the contract clauses describing causal relations between call arguments and the returned value.