Skip to content

Commit a04f57b

Browse files
committed
Fix potential NPE in MulticastPulseClient
cf. #2521 (comment)
1 parent ce387cb commit a04f57b

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

server/openejb-client/src/main/java/org/apache/openejb/client/MulticastPulseClient.java

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -681,51 +681,53 @@ public static void main(final String[] args) throws Exception {
681681
System.err.println(e.getMessage());
682682
}
683683

684-
final int size = uriSet.size();
685-
if (uriSet != null && size > 0) {
684+
if(uriSet != null) {
685+
final int size = uriSet.size();
686+
if (size > 0) {
686687

687-
final int st = (timeout / size);
688+
final int st = (timeout / size);
688689

689-
for (final URI uri : uriSet) {
690+
for (final URI uri : uriSet) {
690691

691-
final String server = uri.getScheme().replace("mp-", "");
692-
URI uriSub = URI.create(uri.getSchemeSpecificPart());
692+
final String server = uri.getScheme().replace("mp-", "");
693+
URI uriSub = URI.create(uri.getSchemeSpecificPart());
693694

694-
final String group = uriSub.getScheme();
695-
uriSub = URI.create(uriSub.getSchemeSpecificPart());
695+
final String group = uriSub.getScheme();
696+
uriSub = URI.create(uriSub.getSchemeSpecificPart());
696697

697-
final String host = uriSub.getHost();
698-
final int port = uriSub.getPort();
698+
final String host = uriSub.getHost();
699+
final int port = uriSub.getPort();
699700

700-
if (MulticastPulseClient.isLocalAddress(host, false) && !MulticastPulseClient.isLocalAddress(server, false)) {
701-
System.out.println(server + ":" + group + " - " + uriSub.toASCIIString() + " is not a local service");
702-
continue;
703-
}
701+
if (MulticastPulseClient.isLocalAddress(host, false) && !MulticastPulseClient.isLocalAddress(server, false)) {
702+
System.out.println(server + ":" + group + " - " + uriSub.toASCIIString() + " is not a local service");
703+
continue;
704+
}
704705

705-
System.out.print(server + ":" + group + " - " + uriSub.toASCIIString() + " is reachable: ");
706+
System.out.print(server + ":" + group + " - " + uriSub.toASCIIString() + " is reachable: ");
706707

707-
boolean b = false;
708-
final Socket s = new Socket();
709-
try {
710-
s.connect(new InetSocketAddress(host, port), st);
711-
b = true;
712-
} catch (Exception e) {
713-
if (java.net.SocketTimeoutException.class.isInstance(e) || SocketException.class.isInstance(e)) {
714-
MulticastPulseClient.broadcastBadUri(group, uriSub, mchost, mcport);
715-
System.out.print("" + e + " : ");
716-
}
717-
} finally {
708+
boolean b = false;
709+
final Socket s = new Socket();
718710
try {
719-
s.close();
711+
s.connect(new InetSocketAddress(host, port), st);
712+
b = true;
720713
} catch (Exception e) {
721-
//Ignore
714+
if (java.net.SocketTimeoutException.class.isInstance(e) || SocketException.class.isInstance(e)) {
715+
MulticastPulseClient.broadcastBadUri(group, uriSub, mchost, mcport);
716+
System.out.print("" + e + " : ");
717+
}
718+
} finally {
719+
try {
720+
s.close();
721+
} catch (Exception e) {
722+
//Ignore
723+
}
722724
}
723-
}
724725

725-
System.out.println(b);
726+
System.out.println(b);
727+
}
728+
} else {
729+
System.out.println("### Failed to discover server: " + discover);
726730
}
727-
} else {
728-
System.out.println("### Failed to discover server: " + discover);
729731
}
730732

731733
System.out.println(".");

0 commit comments

Comments
 (0)