Code review comment: [SpotBugs-P1] Reliance on default encoding: Found a call to a method which will perform a byte to String (or String to byte) conversion, and will assume that the default platform encoding is suitable. 

Code before review:
private void runSendLoop() {
synchronized(this.pendingSendsSyncLock) {
if (this.isSendLoopRunning) {
return;
} else {
this.isSendLoopRunning = true;
}
}
TRACE_LOGGER.debug("Starting requestResponseLink {} internal sender send loop", this.parent.linkPath);
try {
while(this.sendLink != null && this.sendLink.getLocalState() == EndpointState.ACTIVE && this.sendLink.getRemoteState() == EndpointState.ACTIVE && this.availableCredit.get() > 0) {
String requestIdToBeSent;
synchronized(pendingSendsSyncLock) {
requestIdToBeSent = this.pendingRetrySends.poll();
if (requestIdToBeSent == null) {
requestIdToBeSent = this.pendingFreshSends.poll();
if (requestIdToBeSent == null) {
this.isSendLoopRunning = false;
TRACE_LOGGER.debug("RequestResponseLink {} internal sender send loop ending as there are no more requests enqueued.", this.parent.linkPath);
break;
}
}
}
RequestResponseWorkItem requestToBeSent = this.parent.pendingRequests.get(requestIdToBeSent);
if (requestToBeSent != null) {
Delivery delivery = this.sendLink.delivery(UUID.randomUUID().toString().getBytes(UTF_8));
delivery.setMessageFormat(DeliveryImpl.DEFAULT_MESSAGE_FORMAT);
TransactionContext transaction = requestToBeSent.getTransaction();
if (transaction != TransactionContext.NULL_TXN) {
TransactionalState transactionalState = new TransactionalState();
transactionalState.setTxnId(new Binary(transaction.getTransactionId().array()));
delivery.disposition(transactionalState);
}
Pair<byte[], Integer> encodedPair = null;
try {
encodedPair = Util.encodeMessageToOptimalSizeArray(requestToBeSent.getRequest(), this.maxMessageSize);
} catch (PayloadSizeExceededException exception) {
this.parent.exceptionallyCompleteRequest((String)requestToBeSent.getRequest().getMessageId(), new PayloadSizeExceededException(String.format("Size of the payload exceeded Maximum message size: %s kb", this.maxMessageSize / 1024), exception), false);
}
try {
int sentMsgSize = this.sendLink.send(encodedPair.getFirstItem(), 0, encodedPair.getSecondItem());
assert sentMsgSize == encodedPair.getSecondItem() : "Contract of the ProtonJ library for Sender.Send API changed";
delivery.settle();
this.availableCredit.decrementAndGet();
TRACE_LOGGER.debug("RequestResonseLink {} internal sender sent a request. available credit :{}", this.parent.linkPath, this.availableCredit.get());
} catch(Exception e) {
TRACE_LOGGER.error("RequestResonseLink {} failed to send request with request id:{}.", this.parent.linkPath, requestIdToBeSent, e);
this.parent.exceptionallyCompleteRequest(requestIdToBeSent, e, false);
}
} else {
TRACE_LOGGER.warn("Request with id:{} not found in the requestresponse link.", requestIdToBeSent);
}
}
} finally {
synchronized (this.pendingSendsSyncLock) {
if (this.isSendLoopRunning) {
this.isSendLoopRunning = false;
}
}
TRACE_LOGGER.debug("RequestResponseLink {} internal sender send loop stopped.", this.parent.linkPath);
}
}

Line under review: Delivery delivery = this.sendLink.delivery(UUID.randomUUID().toString().getBytes(UTF_8));

Code after addressing the review:
private void runSendLoop() {
synchronized (this.pendingSendsSyncLock) {
if (this.isSendLoopRunning) {
return;
} else {
this.isSendLoopRunning = true;
}
}
TRACE_LOGGER.debug("Starting requestResponseLink {} internal sender send loop", this.parent.linkPath);
try {
while (this.sendLink != null && this.sendLink.getLocalState() == EndpointState.ACTIVE && this.sendLink.getRemoteState() == EndpointState.ACTIVE && this.availableCredit.get() > 0) {
String requestIdToBeSent;
synchronized (pendingSendsSyncLock) {
requestIdToBeSent = this.pendingRetrySends.poll();
if (requestIdToBeSent == null) {
requestIdToBeSent = this.pendingFreshSends.poll();
if (requestIdToBeSent == null) {
this.isSendLoopRunning = false;
TRACE_LOGGER.debug("RequestResponseLink {} internal sender send loop ending as there are no more requests enqueued.", this.parent.linkPath);
break;
}
}
}
RequestResponseWorkItem requestToBeSent = this.parent.pendingRequests.get(requestIdToBeSent);
if (requestToBeSent != null) {
Delivery delivery = this.sendLink.delivery(UUID.randomUUID().toString().getBytes(UTF_8));
delivery.setMessageFormat(DeliveryImpl.DEFAULT_MESSAGE_FORMAT);
TransactionContext transaction = requestToBeSent.getTransaction();
if (transaction != TransactionContext.NULL_TXN) {
TransactionalState transactionalState = new TransactionalState();
transactionalState.setTxnId(new Binary(transaction.getTransactionId().array()));
delivery.disposition(transactionalState);
}
Pair<byte[], Integer> encodedPair = null;
try {
encodedPair = Util.encodeMessageToOptimalSizeArray(requestToBeSent.getRequest(), this.maxMessageSize);
} catch (PayloadSizeExceededException exception) {
this.parent.exceptionallyCompleteRequest((String)requestToBeSent.getRequest().getMessageId(), new PayloadSizeExceededException(String.format("Size of the payload exceeded Maximum message size: %s kb", this.maxMessageSize / 1024), exception), false);
}
try {
int sentMsgSize = this.sendLink.send(encodedPair.getFirstItem(), 0, encodedPair.getSecondItem());
assert sentMsgSize == encodedPair.getSecondItem() : "Contract of the ProtonJ library for Sender.Send API changed";
delivery.settle();
this.availableCredit.decrementAndGet();
TRACE_LOGGER.debug("RequestResonseLink {} internal sender sent a request. available credit :{}", this.parent.linkPath, this.availableCredit.get());
} catch(Exception e) {
TRACE_LOGGER.error("RequestResonseLink {} failed to send request with request id:{}.", this.parent.linkPath, requestIdToBeSent, e);
this.parent.exceptionallyCompleteRequest(requestIdToBeSent, e, false);
}
} else {
TRACE_LOGGER.warn("Request with id:{} not found in the requestresponse link.", requestIdToBeSent);
}
}
} finally {
synchronized (this.pendingSendsSyncLock) {
if (this.isSendLoopRunning) {
this.isSendLoopRunning = false;
}
}
TRACE_LOGGER.debug("RequestResponseLink {} internal sender send loop stopped.", this.parent.linkPath);
}
}