Skip to content

Commit

Permalink
Fix null pointer exception when 'infoRecord' is null
Browse files Browse the repository at this point in the history
  • Loading branch information
dsplayerX committed Oct 24, 2023
1 parent 4460551 commit bca1b13
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,14 @@ private TransactionLocalContext(String globalTransactionId, String url, String p
this.rollbackOnlyError = null;
this.isTransactional = true;
this.transactionId = ValueCreator.createArrayValue(globalTransactionId.getBytes());
transactionResourceManager.transactionInfoMap.put(ByteBuffer.wrap(transactionId.getBytes().clone()),
infoRecord);
validateAndPutTransactionInfo(ByteBuffer.wrap(transactionId.getBytes().clone()), infoRecord);
}

Check warning on line 68 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java#L67-L68

Added lines #L67 - L68 were not covered by tests

private void validateAndPutTransactionInfo(ByteBuffer transactionIdBytes, Object infoRecord) {
if (infoRecord == null) {
return;

Check warning on line 72 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java#L72

Added line #L72 was not covered by tests
}
transactionResourceManager.transactionInfoMap.put(transactionIdBytes, infoRecord);

Check warning on line 74 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java#L74

Added line #L74 was not covered by tests
}

public static TransactionLocalContext createTransactionParticipantLocalCtx(String globalTransactionId,
Expand Down Expand Up @@ -228,7 +234,7 @@ public void setResourceParticipant(boolean resourceParticipant) {
}

public Object getInfoRecord() {
return transactionResourceManager.transactionInfoMap.get(ByteBuffer.wrap(transactionId.getBytes()));
return transactionResourceManager.getTransactionRecord(transactionId);

Check warning on line 237 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java#L237

Added line #L237 was not covered by tests
}

public boolean isTransactional() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,11 @@ public void notifyLocalParticipantFailure(String gTransactionId, String blockId)
}

public Object getTransactionRecord(BArray xid) {
return transactionInfoMap.get(ByteBuffer.wrap(xid.getBytes()));
synchronized (transactionInfoMap) {

Check warning on line 609 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java#L609

Added line #L609 was not covered by tests
if (transactionInfoMap.containsKey(ByteBuffer.wrap(xid.getBytes()))) {
return transactionInfoMap.get(ByteBuffer.wrap(xid.getBytes()));

Check warning on line 611 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java#L611

Added line #L611 was not covered by tests
}
return null;

Check warning on line 613 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java#L613

Added line #L613 was not covered by tests
}
}
}

0 comments on commit bca1b13

Please sign in to comment.