diff --git a/src/main/java/org/ice4j/TransportAddress.java b/src/main/java/org/ice4j/TransportAddress.java index 7f1d826b..cbe29b44 100644 --- a/src/main/java/org/ice4j/TransportAddress.java +++ b/src/main/java/org/ice4j/TransportAddress.java @@ -161,6 +161,15 @@ private String toString(boolean redact) if (redact) { hostAddress = getRedactedAddress(); + if (hostAddress == null) + { + String hostName = getHostName(); + if (hostName != null) + { + /* The transport address is an unresolved hostname. Redact the hostname. */ + hostAddress = "xxxx.xxx"; + } + } } else { @@ -170,6 +179,11 @@ private String toString(boolean redact) hostAddress = getHostName(); } } + if (hostAddress == null) + { + // The address has neither a hostName nor a hostAddress. Shouldn't happen, but don't NPE if it does. */ + hostAddress = "null"; + } StringBuilder bldr = new StringBuilder(hostAddress); @@ -204,7 +218,15 @@ public String getRedactedAddress() { if (AgentConfig.config.getRedactRemoteAddresses()) { - return toRedactedString(getAddress()); + InetAddress addr = getAddress(); + if (addr != null) + { + return toRedactedString(addr); + } + else + { + return null; + } } else { @@ -359,7 +381,7 @@ public static String toRedactedString(InetAddress addr) { return null; } - if (addr.isLoopbackAddress()) + if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) { return addr.getHostAddress(); } @@ -367,7 +389,8 @@ public static String toRedactedString(InetAddress addr) { StringBuilder sb = new StringBuilder(); byte[] addrBytes = addr.getAddress(); - if ((addrBytes[0] & 0xe0) == 0x20) { + if ((addrBytes[0] & 0xe0) == 0x20) + { /* Globally-routable IPv6 address; the second nybble can indicate the * RIR that allocated the address, so don't print it. */ diff --git a/src/main/java/org/ice4j/ice/Component.java b/src/main/java/org/ice4j/ice/Component.java index 5ec65444..85a1693d 100644 --- a/src/main/java/org/ice4j/ice/Component.java +++ b/src/main/java/org/ice4j/ice/Component.java @@ -603,11 +603,11 @@ public String toString() buff.append("\ndefault remote candidate: "); if (defaultRemoteCandidate != null) { - buff.append(getDefaultRemoteCandidate().toRedactedString()); + buff.append(defaultRemoteCandidate.toRedactedString()); } else { - buff.append((String)null); + buff.append("null"); } synchronized(remoteCandidates)