diff --git a/spring-core/src/main/java/org/springframework/lang/Contract.java b/spring-core/src/main/java/org/springframework/lang/Contract.java index 416b6ff4f2..1967b6548f 100644 --- a/spring-core/src/main/java/org/springframework/lang/Contract.java +++ b/spring-core/src/main/java/org/springframework/lang/Contract.java @@ -23,11 +23,14 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * Inspired from {@code org.jetbrains.annotations.Contract}, this variant has been introduce in the - * {@code org.springframework.lang} package to avoid requiring an extra dependency, while still following the same semantics. + *
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. * - *
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. + *
Inspired from {@code org.jetbrains.annotations.Contract}, this variant has + * been introduce in the {@code org.springframework.lang} package to avoid requiring + * an extra dependency, while still following the same semantics. * *
Method contract has the following syntax:
* contract ::= (clause ';')* clause
@@ -39,21 +42,26 @@ import java.lang.annotation.Target;
*
* The constraints denote the following:
*
_
- any valuenull
- null value!null
- a value statically proved to be not-nulltrue
- true boolean valuefalse
- false boolean valuefail
- the method throws an exception, if the arguments satisfy argument
+ * constraintsExamples:
- * @Contract("_, null -> null")
- method returns null if its second argument is null
- * @Contract("_, null -> null; _, !null -> !null")
- 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("_, null -> null")
- method returns null if its second
+ * argument is null
+ * @Contract("_, null -> null; _, !null -> !null")
- 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
*
* @author Sebastien Deleuze
* @since 6.2
- * @see NullAway custom contract annotations
+ * @see
+ * NullAway custom contract annotations
*/
@Documented
@Retention(RetentionPolicy.CLASS)