Skip to content

Commit 251b166

Browse files
committed
Annotate BatchStatement and Statement methods with CheckReturnValue
Since the driver's default implementation is for BatchStatement methods to be immutable, we should annotate those methods with @CheckReturnValue. Additionally, all Statement#setNowInSeconds implementations are immutable so annotate that too.
1 parent db4c807 commit 251b166

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

core/revapi.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6956,6 +6956,62 @@
69566956
"old": "method java.lang.Throwable java.lang.Throwable::fillInStackTrace() @ com.fasterxml.jackson.databind.deser.UnresolvedForwardReference",
69576957
"new": "method com.fasterxml.jackson.databind.deser.UnresolvedForwardReference com.fasterxml.jackson.databind.deser.UnresolvedForwardReference::fillInStackTrace()",
69586958
"justification": "Upgrade jackson-databind to 2.13.4.1 to address CVEs, API change cause: https://github.com/FasterXML/jackson-databind/issues/3419"
6959+
},
6960+
{
6961+
"code": "java.annotation.added",
6962+
"old": "method SelfT com.datastax.oss.driver.api.core.cql.Statement<SelfT extends com.datastax.oss.driver.api.core.cql.Statement<SelfT extends com.datastax.oss.driver.api.core.cql.Statement<SelfT>>>::setNowInSeconds(int)",
6963+
"new": "method SelfT com.datastax.oss.driver.api.core.cql.Statement<SelfT extends com.datastax.oss.driver.api.core.cql.Statement<SelfT extends com.datastax.oss.driver.api.core.cql.Statement<SelfT>>>::setNowInSeconds(int)",
6964+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
6965+
"justification": "Annotate mutating methods with @CheckReturnValue"
6966+
},
6967+
{
6968+
"code": "java.annotation.added",
6969+
"old": "method com.datastax.oss.driver.api.core.cql.BatchStatement com.datastax.oss.driver.api.core.cql.BatchStatement::add(com.datastax.oss.driver.api.core.cql.BatchableStatement<?>)",
6970+
"new": "method com.datastax.oss.driver.api.core.cql.BatchStatement com.datastax.oss.driver.api.core.cql.BatchStatement::add(com.datastax.oss.driver.api.core.cql.BatchableStatement<?>)",
6971+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
6972+
"justification": "Annotate mutating methods with @CheckReturnValue"
6973+
},
6974+
{
6975+
"code": "java.annotation.added",
6976+
"old": "method com.datastax.oss.driver.api.core.cql.BatchStatement com.datastax.oss.driver.api.core.cql.BatchStatement::addAll(com.datastax.oss.driver.api.core.cql.BatchableStatement<?>[])",
6977+
"new": "method com.datastax.oss.driver.api.core.cql.BatchStatement com.datastax.oss.driver.api.core.cql.BatchStatement::addAll(com.datastax.oss.driver.api.core.cql.BatchableStatement<?>[])",
6978+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
6979+
"justification": "Annotate mutating methods with @CheckReturnValue"
6980+
},
6981+
{
6982+
"code": "java.annotation.added",
6983+
"old": "method com.datastax.oss.driver.api.core.cql.BatchStatement com.datastax.oss.driver.api.core.cql.BatchStatement::addAll(java.lang.Iterable<? extends com.datastax.oss.driver.api.core.cql.BatchableStatement<?>>)",
6984+
"new": "method com.datastax.oss.driver.api.core.cql.BatchStatement com.datastax.oss.driver.api.core.cql.BatchStatement::addAll(java.lang.Iterable<? extends com.datastax.oss.driver.api.core.cql.BatchableStatement<?>>)",
6985+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
6986+
"justification": "Annotate mutating methods with @CheckReturnValue"
6987+
},
6988+
{
6989+
"code": "java.annotation.added",
6990+
"old": "method com.datastax.oss.driver.api.core.cql.BatchStatement com.datastax.oss.driver.api.core.cql.BatchStatement::clear()",
6991+
"new": "method com.datastax.oss.driver.api.core.cql.BatchStatement com.datastax.oss.driver.api.core.cql.BatchStatement::clear()",
6992+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
6993+
"justification": "Annotate mutating methods with @CheckReturnValue"
6994+
},
6995+
{
6996+
"code": "java.annotation.added",
6997+
"old": "method com.datastax.oss.driver.api.core.cql.BatchStatement com.datastax.oss.driver.api.core.cql.BatchStatement::setBatchType(com.datastax.oss.driver.api.core.cql.BatchType)",
6998+
"new": "method com.datastax.oss.driver.api.core.cql.BatchStatement com.datastax.oss.driver.api.core.cql.BatchStatement::setBatchType(com.datastax.oss.driver.api.core.cql.BatchType)",
6999+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
7000+
"justification": "Annotate mutating methods with @CheckReturnValue"
7001+
},
7002+
{
7003+
"code": "java.annotation.added",
7004+
"old": "method com.datastax.oss.driver.api.core.cql.BatchStatement com.datastax.oss.driver.api.core.cql.BatchStatement::setKeyspace(com.datastax.oss.driver.api.core.CqlIdentifier)",
7005+
"new": "method com.datastax.oss.driver.api.core.cql.BatchStatement com.datastax.oss.driver.api.core.cql.BatchStatement::setKeyspace(com.datastax.oss.driver.api.core.CqlIdentifier)",
7006+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
7007+
"justification": "JAVA-2161: Annotate mutating methods with @CheckReturnValue"
7008+
},
7009+
{
7010+
"code": "java.annotation.added",
7011+
"old": "method com.datastax.oss.driver.api.core.cql.BatchStatement com.datastax.oss.driver.api.core.cql.BatchStatement::setKeyspace(java.lang.String)",
7012+
"new": "method com.datastax.oss.driver.api.core.cql.BatchStatement com.datastax.oss.driver.api.core.cql.BatchStatement::setKeyspace(java.lang.String)",
7013+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
7014+
"justification": "JAVA-2161: Annotate mutating methods with @CheckReturnValue"
69597015
}
69607016
]
69617017
}

core/src/main/java/com/datastax/oss/driver/api/core/cql/BatchStatement.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.datastax.oss.driver.internal.core.util.Sizes;
2727
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList;
2828
import com.datastax.oss.protocol.internal.PrimitiveSizes;
29+
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
2930
import edu.umd.cs.findbugs.annotations.NonNull;
3031
import edu.umd.cs.findbugs.annotations.Nullable;
3132
import java.util.ArrayList;
@@ -164,6 +165,7 @@ static BatchStatementBuilder builder(@NonNull BatchStatement template) {
164165
* method. However custom implementations may choose to be mutable and return the same instance.
165166
*/
166167
@NonNull
168+
@CheckReturnValue
167169
BatchStatement setBatchType(@NonNull BatchType newBatchType);
168170

169171
/**
@@ -180,13 +182,15 @@ static BatchStatementBuilder builder(@NonNull BatchStatement template) {
180182
* @see Request#getKeyspace()
181183
*/
182184
@NonNull
185+
@CheckReturnValue
183186
BatchStatement setKeyspace(@Nullable CqlIdentifier newKeyspace);
184187

185188
/**
186189
* Shortcut for {@link #setKeyspace(CqlIdentifier)
187190
* setKeyspace(CqlIdentifier.fromCql(newKeyspaceName))}.
188191
*/
189192
@NonNull
193+
@CheckReturnValue
190194
default BatchStatement setKeyspace(@NonNull String newKeyspaceName) {
191195
return setKeyspace(CqlIdentifier.fromCql(newKeyspaceName));
192196
}
@@ -201,6 +205,7 @@ default BatchStatement setKeyspace(@NonNull String newKeyspaceName) {
201205
* method. However custom implementations may choose to be mutable and return the same instance.
202206
*/
203207
@NonNull
208+
@CheckReturnValue
204209
BatchStatement add(@NonNull BatchableStatement<?> statement);
205210

206211
/**
@@ -213,10 +218,12 @@ default BatchStatement setKeyspace(@NonNull String newKeyspaceName) {
213218
* method. However custom implementations may choose to be mutable and return the same instance.
214219
*/
215220
@NonNull
221+
@CheckReturnValue
216222
BatchStatement addAll(@NonNull Iterable<? extends BatchableStatement<?>> statements);
217223

218224
/** @see #addAll(Iterable) */
219225
@NonNull
226+
@CheckReturnValue
220227
default BatchStatement addAll(@NonNull BatchableStatement<?>... statements) {
221228
return addAll(Arrays.asList(statements));
222229
}
@@ -231,6 +238,7 @@ default BatchStatement addAll(@NonNull BatchableStatement<?>... statements) {
231238
* method. However custom implementations may choose to be mutable and return the same instance.
232239
*/
233240
@NonNull
241+
@CheckReturnValue
234242
BatchStatement clear();
235243

236244
@Override

core/src/main/java/com/datastax/oss/driver/api/core/cql/Statement.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ default int getNowInSeconds() {
513513
* @see #NO_NOW_IN_SECONDS
514514
*/
515515
@NonNull
516+
@CheckReturnValue
516517
@SuppressWarnings("unchecked")
517518
default SelfT setNowInSeconds(int nowInSeconds) {
518519
return (SelfT) this;

0 commit comments

Comments
 (0)