Skip to content

Commit ad83431

Browse files
committed
Annotate BatchStatement, Statement, SimpleStatement methods with CheckReturnValue
Since the driver's default implementation is for BatchStatement and SimpleStatement methods to be immutable, we should annotate those methods with @CheckReturnValue. Statement#setNowInSeconds implementations are immutable so annotate that too. patch by Ammar Khaku; reviewed by Andy Tolbert and Bret McGuire for PR 1607
1 parent 6d3ba47 commit ad83431

File tree

4 files changed

+149
-0
lines changed

4 files changed

+149
-0
lines changed

core/revapi.json

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6956,6 +6956,139 @@
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>>::setNowInSeconds(int) @ com.datastax.oss.driver.api.core.cql.BatchStatement",
6963+
"new": "method SelfT com.datastax.oss.driver.api.core.cql.Statement<SelfT extends com.datastax.oss.driver.api.core.cql.Statement<SelfT>>::setNowInSeconds(int) @ com.datastax.oss.driver.api.core.cql.BatchStatement",
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 SelfT com.datastax.oss.driver.api.core.cql.Statement<SelfT extends com.datastax.oss.driver.api.core.cql.Statement<SelfT>>::setNowInSeconds(int) @ com.datastax.oss.driver.api.core.cql.BatchableStatement<SelfT extends com.datastax.oss.driver.api.core.cql.BatchableStatement<SelfT>>",
6970+
"new": "method SelfT com.datastax.oss.driver.api.core.cql.Statement<SelfT extends com.datastax.oss.driver.api.core.cql.Statement<SelfT>>::setNowInSeconds(int) @ com.datastax.oss.driver.api.core.cql.BatchStatement",
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 SelfT com.datastax.oss.driver.api.core.cql.Statement<SelfT extends com.datastax.oss.driver.api.core.cql.Statement<SelfT>>::setNowInSeconds(int) @ com.datastax.oss.driver.api.core.cql.BatchableStatement<SelfT extends com.datastax.oss.driver.api.core.cql.BatchableStatement<SelfT>>",
6977+
"new": "method SelfT com.datastax.oss.driver.api.core.cql.Statement<SelfT extends com.datastax.oss.driver.api.core.cql.Statement<SelfT>>::setNowInSeconds(int) @ com.datastax.oss.driver.api.core.cql.BatchableStatement<SelfT extends com.datastax.oss.driver.api.core.cql.BatchableStatement<SelfT>>",
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 SelfT com.datastax.oss.driver.api.core.cql.Statement<SelfT extends com.datastax.oss.driver.api.core.cql.Statement<SelfT>>::setNowInSeconds(int) @ com.datastax.oss.driver.api.core.cql.BoundStatement",
6984+
"new": "method SelfT com.datastax.oss.driver.api.core.cql.Statement<SelfT extends com.datastax.oss.driver.api.core.cql.Statement<SelfT>>::setNowInSeconds(int) @ com.datastax.oss.driver.api.core.cql.BoundStatement",
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 SelfT com.datastax.oss.driver.api.core.cql.Statement<SelfT extends com.datastax.oss.driver.api.core.cql.Statement<SelfT>>::setNowInSeconds(int) @ com.datastax.oss.driver.api.core.cql.SimpleStatement",
6991+
"new": "method SelfT com.datastax.oss.driver.api.core.cql.Statement<SelfT extends com.datastax.oss.driver.api.core.cql.Statement<SelfT>>::setNowInSeconds(int) @ com.datastax.oss.driver.api.core.cql.SimpleStatement",
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 SelfT com.datastax.oss.driver.api.core.cql.Statement<SelfT extends com.datastax.oss.driver.api.core.cql.Statement<SelfT>>::setNowInSeconds(int)",
6998+
"new": "method SelfT com.datastax.oss.driver.api.core.cql.Statement<SelfT extends com.datastax.oss.driver.api.core.cql.Statement<SelfT>>::setNowInSeconds(int)",
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::add(com.datastax.oss.driver.api.core.cql.BatchableStatement<?>)",
7005+
"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<?>)",
7006+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
7007+
"justification": "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::addAll(com.datastax.oss.driver.api.core.cql.BatchableStatement<?>[])",
7012+
"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<?>[])",
7013+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
7014+
"justification": "Annotate mutating methods with @CheckReturnValue"
7015+
},
7016+
{
7017+
"code": "java.annotation.added",
7018+
"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<?>>)",
7019+
"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<?>>)",
7020+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
7021+
"justification": "Annotate mutating methods with @CheckReturnValue"
7022+
},
7023+
{
7024+
"code": "java.annotation.added",
7025+
"old": "method com.datastax.oss.driver.api.core.cql.BatchStatement com.datastax.oss.driver.api.core.cql.BatchStatement::clear()",
7026+
"new": "method com.datastax.oss.driver.api.core.cql.BatchStatement com.datastax.oss.driver.api.core.cql.BatchStatement::clear()",
7027+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
7028+
"justification": "Annotate mutating methods with @CheckReturnValue"
7029+
},
7030+
{
7031+
"code": "java.annotation.added",
7032+
"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)",
7033+
"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)",
7034+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
7035+
"justification": "Annotate mutating methods with @CheckReturnValue"
7036+
},
7037+
{
7038+
"code": "java.annotation.added",
7039+
"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)",
7040+
"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)",
7041+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
7042+
"justification": "JAVA-2161: Annotate mutating methods with @CheckReturnValue"
7043+
},
7044+
{
7045+
"code": "java.annotation.added",
7046+
"old": "method com.datastax.oss.driver.api.core.cql.BatchStatement com.datastax.oss.driver.api.core.cql.BatchStatement::setKeyspace(java.lang.String)",
7047+
"new": "method com.datastax.oss.driver.api.core.cql.BatchStatement com.datastax.oss.driver.api.core.cql.BatchStatement::setKeyspace(java.lang.String)",
7048+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
7049+
"justification": "JAVA-2161: Annotate mutating methods with @CheckReturnValue"
7050+
},
7051+
{
7052+
"code": "java.annotation.added",
7053+
"old": "method com.datastax.oss.driver.api.core.cql.SimpleStatement com.datastax.oss.driver.api.core.cql.SimpleStatement::setQuery(java.lang.String)",
7054+
"new": "method com.datastax.oss.driver.api.core.cql.SimpleStatement com.datastax.oss.driver.api.core.cql.SimpleStatement::setQuery(java.lang.String)",
7055+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
7056+
"justification": "Annotate mutating methods with @CheckReturnValue"
7057+
},
7058+
{
7059+
"code": "java.annotation.added",
7060+
"old": "method com.datastax.oss.driver.api.core.cql.SimpleStatement com.datastax.oss.driver.api.core.cql.SimpleStatement::setKeyspace(com.datastax.oss.driver.api.core.CqlIdentifier)",
7061+
"new": "method com.datastax.oss.driver.api.core.cql.SimpleStatement com.datastax.oss.driver.api.core.cql.SimpleStatement::setKeyspace(com.datastax.oss.driver.api.core.CqlIdentifier)",
7062+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
7063+
"justification": "Annotate mutating methods with @CheckReturnValue"
7064+
},
7065+
{
7066+
"code": "java.annotation.added",
7067+
"old": "method com.datastax.oss.driver.api.core.cql.SimpleStatement com.datastax.oss.driver.api.core.cql.SimpleStatement::setKeyspace(java.lang.String)",
7068+
"new": "method com.datastax.oss.driver.api.core.cql.SimpleStatement com.datastax.oss.driver.api.core.cql.SimpleStatement::setKeyspace(java.lang.String)",
7069+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
7070+
"justification": "Annotate mutating methods with @CheckReturnValue"
7071+
},
7072+
{
7073+
"code": "java.annotation.added",
7074+
"old": "method com.datastax.oss.driver.api.core.cql.SimpleStatement com.datastax.oss.driver.api.core.cql.SimpleStatement::setPositionalValues(java.util.List<java.lang.Object>)",
7075+
"new": "method com.datastax.oss.driver.api.core.cql.SimpleStatement com.datastax.oss.driver.api.core.cql.SimpleStatement::setPositionalValues(java.util.List<java.lang.Object>)",
7076+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
7077+
"justification": "Annotate mutating methods with @CheckReturnValue"
7078+
},
7079+
{
7080+
"code": "java.annotation.added",
7081+
"old": "method com.datastax.oss.driver.api.core.cql.SimpleStatement com.datastax.oss.driver.api.core.cql.SimpleStatement::setNamedValuesWithIds(java.util.Map<com.datastax.oss.driver.api.core.CqlIdentifier, java.lang.Object>)",
7082+
"new": "method com.datastax.oss.driver.api.core.cql.SimpleStatement com.datastax.oss.driver.api.core.cql.SimpleStatement::setNamedValuesWithIds(java.util.Map<com.datastax.oss.driver.api.core.CqlIdentifier, java.lang.Object>)",
7083+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
7084+
"justification": "Annotate mutating methods with @CheckReturnValue"
7085+
},
7086+
{
7087+
"code": "java.annotation.added",
7088+
"old": "method com.datastax.oss.driver.api.core.cql.SimpleStatement com.datastax.oss.driver.api.core.cql.SimpleStatement::setNamedValues(java.util.Map<java.lang.String, java.lang.Object>)",
7089+
"new": "method com.datastax.oss.driver.api.core.cql.SimpleStatement com.datastax.oss.driver.api.core.cql.SimpleStatement::setNamedValues(java.util.Map<java.lang.String, java.lang.Object>)",
7090+
"annotation": "@edu.umd.cs.findbugs.annotations.CheckReturnValue",
7091+
"justification": "Annotate mutating methods with @CheckReturnValue"
69597092
}
69607093
]
69617094
}

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/SimpleStatement.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.datastax.oss.protocol.internal.PrimitiveSizes;
2929
import com.datastax.oss.protocol.internal.util.collection.NullAllowingImmutableList;
3030
import com.datastax.oss.protocol.internal.util.collection.NullAllowingImmutableMap;
31+
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
3132
import edu.umd.cs.findbugs.annotations.NonNull;
3233
import edu.umd.cs.findbugs.annotations.Nullable;
3334
import java.util.List;
@@ -197,6 +198,7 @@ static SimpleStatementBuilder builder(@NonNull SimpleStatement template) {
197198
* @see #setNamedValuesWithIds(Map)
198199
*/
199200
@NonNull
201+
@CheckReturnValue
200202
SimpleStatement setQuery(@NonNull String newQuery);
201203

202204
/**
@@ -209,13 +211,15 @@ static SimpleStatementBuilder builder(@NonNull SimpleStatement template) {
209211
* @see Request#getKeyspace()
210212
*/
211213
@NonNull
214+
@CheckReturnValue
212215
SimpleStatement setKeyspace(@Nullable CqlIdentifier newKeyspace);
213216

214217
/**
215218
* Shortcut for {@link #setKeyspace(CqlIdentifier)
216219
* setKeyspace(CqlIdentifier.fromCql(newKeyspaceName))}.
217220
*/
218221
@NonNull
222+
@CheckReturnValue
219223
default SimpleStatement setKeyspace(@NonNull String newKeyspaceName) {
220224
return setKeyspace(CqlIdentifier.fromCql(newKeyspaceName));
221225
}
@@ -236,6 +240,7 @@ default SimpleStatement setKeyspace(@NonNull String newKeyspaceName) {
236240
* @see #setQuery(String)
237241
*/
238242
@NonNull
243+
@CheckReturnValue
239244
SimpleStatement setPositionalValues(@NonNull List<Object> newPositionalValues);
240245

241246
@NonNull
@@ -256,13 +261,15 @@ default SimpleStatement setKeyspace(@NonNull String newKeyspaceName) {
256261
* @see #setQuery(String)
257262
*/
258263
@NonNull
264+
@CheckReturnValue
259265
SimpleStatement setNamedValuesWithIds(@NonNull Map<CqlIdentifier, Object> newNamedValues);
260266

261267
/**
262268
* Shortcut for {@link #setNamedValuesWithIds(Map)} with raw strings as value names. The keys are
263269
* converted on the fly with {@link CqlIdentifier#fromCql(String)}.
264270
*/
265271
@NonNull
272+
@CheckReturnValue
266273
default SimpleStatement setNamedValues(@NonNull Map<String, Object> newNamedValues) {
267274
return setNamedValuesWithIds(DefaultSimpleStatement.wrapKeys(newNamedValues));
268275
}

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)