22
22
import java .util .concurrent .atomic .AtomicReferenceArray ;
23
23
import java .util .function .Predicate ;
24
24
25
+ import javax .annotation .Nonnull ;
26
+
25
27
import com .google .common .annotations .VisibleForTesting ;
28
+ import com .google .common .base .Preconditions ;
26
29
import com .google .common .base .Predicates ;
27
30
28
31
import org .agrona .concurrent .UnsafeBuffer ;
@@ -296,8 +299,9 @@ private int allocateNewObject()
296
299
* @return A content id that can be used to reference the content, encoded as ~index where index is the
297
300
* position of the value in the content array.
298
301
*/
299
- private int addContent (T value ) throws TrieSpaceExhaustedException
302
+ private int addContent (@ Nonnull T value ) throws TrieSpaceExhaustedException
300
303
{
304
+ Preconditions .checkNotNull (value , "Content value cannot be null" );
301
305
int index = objectAllocator .allocate ();
302
306
int leadBit = getBufferIdx (index , CONTENTS_START_SHIFT , CONTENTS_START_SIZE );
303
307
int ofs = inBufferOffset (index , leadBit , CONTENTS_START_SIZE );
@@ -1329,9 +1333,9 @@ public interface UpsertTransformerWithKeyProducer<T, U>
1329
1333
* @param existing Existing content for this key, or null if there isn't any.
1330
1334
* @param update The update, always non-null.
1331
1335
* @param keyState An interface that can be used to retrieve the path of the value being updated.
1332
- * @return The combined value to use.
1336
+ * @return The combined value to use. Cannot be null.
1333
1337
*/
1334
- T apply (T existing , U update , KeyProducer <T > keyState );
1338
+ @ Nonnull T apply (T existing , @ Nonnull U update , @ Nonnull KeyProducer <T > keyState );
1335
1339
}
1336
1340
1337
1341
/**
@@ -1353,7 +1357,7 @@ public interface UpsertTransformer<T, U> extends UpsertTransformerWithKeyProduce
1353
1357
* @param update The update, always non-null.
1354
1358
* @return The combined value to use. Cannot be null.
1355
1359
*/
1356
- T apply (T existing , U update );
1360
+ @ Nonnull T apply (T existing , @ Nonnull U update );
1357
1361
1358
1362
/**
1359
1363
* Version of the above that also provides the path of a value being updated.
@@ -1363,7 +1367,7 @@ public interface UpsertTransformer<T, U> extends UpsertTransformerWithKeyProduce
1363
1367
* @param keyState An interface that can be used to retrieve the path of the value being updated.
1364
1368
* @return The combined value to use. Cannot be null.
1365
1369
*/
1366
- default T apply (T existing , U update , KeyProducer <T > keyState )
1370
+ default @ Nonnull T apply (T existing , @ Nonnull U update , @ Nonnull KeyProducer <T > keyState )
1367
1371
{
1368
1372
return apply (existing , update );
1369
1373
}
@@ -1441,7 +1445,10 @@ void applyContent() throws TrieSpaceExhaustedException
1441
1445
{
1442
1446
T existingContent = state .getContent ();
1443
1447
T combinedContent = transformer .apply (existingContent , content , state );
1444
- state .setContent (combinedContent , // can be null
1448
+ if (combinedContent == null )
1449
+ throw new AssertionError ("Transformer " + transformer + " returned null content for "
1450
+ + existingContent + ", " + content );
1451
+ state .setContent (combinedContent ,
1445
1452
state .currentDepth >= forcedCopyDepth ); // this is called at the start of processing
1446
1453
}
1447
1454
}
0 commit comments