Skip to content
This repository has been archived by the owner on Nov 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #70 from caskdata/bugfix/tephra-116_nullable-thrif…
Browse files Browse the repository at this point in the history
…t-fields

TEPHRA-116 Defensively check for null fields in deserialized TTransaction
  • Loading branch information
ghelmling committed Aug 1, 2015
2 parents b8e01fc + 8ec2461 commit 5dce56c
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* Utility methods to convert to thrift and back.
*/
public final class TransactionConverterUtils {
private static final long[] EMPTY_LONG_ARRAY = {};

public static TTransaction wrap(Transaction tx) {
return new TTransaction(tx.getTransactionId(), tx.getReadPointer(),
Expand All @@ -38,9 +39,12 @@ public static TTransaction wrap(Transaction tx) {

public static Transaction unwrap(TTransaction thriftTx) {
return new Transaction(thriftTx.getReadPointer(), thriftTx.getTransactionId(), thriftTx.getWritePointer(),
Longs.toArray(thriftTx.getInvalids()), Longs.toArray(thriftTx.getInProgress()),
thriftTx.getInvalids() == null ? EMPTY_LONG_ARRAY : Longs.toArray(thriftTx.getInvalids()),
thriftTx.getInProgress() == null ? EMPTY_LONG_ARRAY :
Longs.toArray(thriftTx.getInProgress()),
thriftTx.getFirstShort(), getTransactionType(thriftTx.getType()),
Longs.toArray(thriftTx.getCheckpointWritePointers()),
thriftTx.getCheckpointWritePointers() == null ? EMPTY_LONG_ARRAY :
Longs.toArray(thriftTx.getCheckpointWritePointers()),
getVisibilityLevel(thriftTx.getVisibilityLevel()));
}

Expand All @@ -53,6 +57,11 @@ private static TTransactionType getTTransactionType(TransactionType type) {
}

private static Transaction.VisibilityLevel getVisibilityLevel(TVisibilityLevel tLevel) {
// default to SNAPSHOT
if (tLevel == null) {
return Transaction.VisibilityLevel.SNAPSHOT;
}

switch (tLevel) {
case SNAPSHOT:
return Transaction.VisibilityLevel.SNAPSHOT;
Expand Down

0 comments on commit 5dce56c

Please sign in to comment.