Skip to content

Commit

Permalink
Fix potential NPE in isLinkOpenAndConnected.
Browse files Browse the repository at this point in the history
Signed-off-by: Carsten Lohmann <[email protected]>
  • Loading branch information
calohmn committed May 12, 2021
1 parent a41ed64 commit 792bf0b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 19 additions & 5 deletions core/src/main/java/org/eclipse/hono/util/HonoProtonHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ public static void setDefaultCloseHandler(final ProtonSession session) {

/**
* Checks if a link is established.
* <p>
* Note that this only applies to a link which has originally been created by the local peer.
*
* @param link The link to check.
* @return {@code true} if the link has been established.
Expand All @@ -178,16 +180,28 @@ public static boolean isLinkOpenAndConnected(final ProtonLink<?> link) {
if (link != null && link.isOpen()) {
if (link.getSession() != null && link.getSession().getConnection() != null
&& !link.getSession().getConnection().isDisconnected()) {
return true;
return true;
}
final String localLinkAddress = link instanceof ProtonSender ? link.getTarget().getAddress()
: link.getSource().getAddress();
LOG.debug("{} link [address: {}] is locally open but underlying transport is disconnected",
link instanceof ProtonSender ? "sender" : "receiver", localLinkAddress);
LOG.debug("{} link [source: {}, target: {}] is locally open but underlying transport is disconnected",
link instanceof ProtonSender ? "sender" : "receiver", getRemoteOrLocalSourceAddress(link), getRemoteOrLocalTargetAddress(link));
}
return false;
}

private static String getRemoteOrLocalSourceAddress(final ProtonLink<?> link) {
if (link != null && link.getRemoteSource() != null) {
return link.getRemoteSource().getAddress();
}
return link != null && link.getSource() != null ? link.getSource().getAddress() : null;
}

private static String getRemoteOrLocalTargetAddress(final ProtonLink<?> link) {
if (link != null && link.getRemoteTarget() != null) {
return link.getRemoteTarget().getAddress();
}
return link != null && link.getTarget() != null ? link.getTarget().getAddress() : null;
}

/**
* Executes some code on a given context.
*
Expand Down
2 changes: 2 additions & 0 deletions site/homepage/content/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ description = "Information about changes in recent Hono releases. Includes new f

* The Quarkus based Command Router native image failed to start an embedded cache that was configured to persist data
to the local file system. This has been fixed.
* The delivery of a command message sent to an AMQP device potentially didn't get settled if the connection to the
AMQP device got disconnected. This has been fixed.

## 1.7.1

Expand Down

0 comments on commit 792bf0b

Please sign in to comment.