Commit 3cef97cb authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

PiggyBackService: fixed null-pointer on piggyback-receive if no local

service is registered.
parent 5964bc4f
...@@ -319,8 +319,7 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent, ...@@ -319,8 +319,7 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent,
for (PiggybackMessageService pService : piggybackServices for (PiggybackMessageService pService : piggybackServices
.values()) { .values()) {
piggybacked = pService.piggybackOnSendMessage(receiverNet, piggybacked = pService.piggybackOnSendMessage(receiverNet,
receiverPort, receiverPort, ProtocolAdapter.this);
ProtocolAdapter.this);
if (piggybacked != null) { if (piggybacked != null) {
if (mPig == null) { if (mPig == null) {
mPig = new MessageWithPiggybackedData(msg); mPig = new MessageWithPiggybackedData(msg);
...@@ -430,7 +429,6 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent, ...@@ -430,7 +429,6 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent,
} }
} }
/* /*
* Notify the Protocol of a received Message * Notify the Protocol of a received Message
*/ */
...@@ -465,7 +463,8 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent, ...@@ -465,7 +463,8 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent,
// triggered once // triggered once
if (receivedMessage.getPayload() instanceof MessageWithPiggybackedData) { if (receivedMessage.getPayload() instanceof MessageWithPiggybackedData) {
MessageWithPiggybackedData pMsg = (MessageWithPiggybackedData) receivedMessage.getPayload(); MessageWithPiggybackedData pMsg = (MessageWithPiggybackedData) receivedMessage
.getPayload();
/* /*
* Deliver piggybacked messages * Deliver piggybacked messages
*/ */
...@@ -478,8 +477,8 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent, ...@@ -478,8 +477,8 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent,
// deliver real message // deliver real message
replyEvent.success(pMsg.getPayload(), senderInfo); replyEvent.success(pMsg.getPayload(), senderInfo);
} else { } else {
replyEvent replyEvent.success(receivedMessage.getPayload(),
.success(receivedMessage.getPayload(), senderInfo); senderInfo);
} }
} }
/* /*
...@@ -497,13 +496,15 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent, ...@@ -497,13 +496,15 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent,
MessageWithPiggybackedData pMsg = (MessageWithPiggybackedData) receivedMessage MessageWithPiggybackedData pMsg = (MessageWithPiggybackedData) receivedMessage
.getPayload(); .getPayload();
/* /*
* Deliver piggybacked messages * Deliver piggybacked messages, but only if we have a local
* listener. Discard otherwise.
*/ */
for (Entry<Byte, Message> entry : pMsg.getPiggybacked() for (Entry<Byte, Message> entry : pMsg.getPiggybacked()
.entrySet()) { .entrySet()) {
piggybackServices.get(entry.getKey()) PiggybackMessageService service = piggybackServices.get(entry.getKey());
.onReceivedPiggybackedMessage(entry.getValue(), if (service != null) {
senderInfo); service.onReceivedPiggybackedMessage(entry.getValue(), senderInfo);
}
} }
// deliver real message // deliver real message
pl.dispatch(pMsg.getPayload(), protocol, senderInfo, pl.dispatch(pMsg.getPayload(), protocol, senderInfo,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment