mirror of https://github.com/apache/nifi.git
NIFI-12358 Fixed NPE in HostHeaderHandler
Fixed NPE in ThreadDumpTask and TrackedLeaderElectionManager This closes #8032 Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
parent
685c6861b3
commit
b5c3e6f9aa
|
@ -25,6 +25,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ThreadDumpTask implements DiagnosticTask {
|
||||
@Override
|
||||
|
@ -37,7 +38,7 @@ public class ThreadDumpTask implements DiagnosticTask {
|
|||
|
||||
final List<ThreadInfo> sortedInfos = new ArrayList<>(infos.length);
|
||||
Collections.addAll(sortedInfos, infos);
|
||||
sortedInfos.sort(new Comparator<ThreadInfo>() {
|
||||
sortedInfos.sort(new Comparator<>() {
|
||||
@Override
|
||||
public int compare(ThreadInfo o1, ThreadInfo o2) {
|
||||
return o1.getThreadName().toLowerCase().compareTo(o2.getThreadName().toLowerCase());
|
||||
|
@ -69,7 +70,7 @@ public class ThreadDumpTask implements DiagnosticTask {
|
|||
sb.append(" (in native code)");
|
||||
}
|
||||
|
||||
if (deadlockedThreadIds != null && deadlockedThreadIds.length > 0) {
|
||||
if (deadlockedThreadIds != null) {
|
||||
for (final long id : deadlockedThreadIds) {
|
||||
if (id == info.getThreadId()) {
|
||||
sb.append(" ** DEADLOCKED THREAD **");
|
||||
|
@ -77,7 +78,7 @@ public class ThreadDumpTask implements DiagnosticTask {
|
|||
}
|
||||
}
|
||||
|
||||
if (monitorDeadlockThreadIds != null && monitorDeadlockThreadIds.length > 0) {
|
||||
if (monitorDeadlockThreadIds != null) {
|
||||
for (final long id : monitorDeadlockThreadIds) {
|
||||
if (id == info.getThreadId()) {
|
||||
sb.append(" ** MONITOR-DEADLOCKED THREAD **");
|
||||
|
@ -91,7 +92,7 @@ public class ThreadDumpTask implements DiagnosticTask {
|
|||
|
||||
final MonitorInfo[] monitors = info.getLockedMonitors();
|
||||
for (final MonitorInfo monitor : monitors) {
|
||||
if (monitor.getLockedStackFrame().equals(element)) {
|
||||
if (Objects.equals(monitor.getLockedStackFrame(), element)) {
|
||||
sb.append("\n\t- waiting on ").append(monitor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public abstract class TrackedLeaderElectionManager implements LeaderElectionMana
|
|||
final TimedBuffer<TimestampedLong> buffer = entry.getValue();
|
||||
|
||||
final TimestampedLong aggregateValue = buffer.getAggregateValue(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(duration, unit));
|
||||
final int leadershipChanges = aggregateValue.getValue().intValue();
|
||||
final int leadershipChanges = (aggregateValue == null) ? 0 : aggregateValue.getValue().intValue();
|
||||
leadershipChangesPerRole.put(roleName, leadershipChanges);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,18 @@
|
|||
*/
|
||||
package org.apache.nifi.web.server;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.apache.http.conn.util.InetAddressUtils;
|
||||
import org.apache.nifi.util.NiFiProperties;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.ScopedHandler;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.InetAddress;
|
||||
|
@ -28,17 +40,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.apache.http.conn.util.InetAddressUtils;
|
||||
import org.apache.nifi.util.NiFiProperties;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.ScopedHandler;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class HostHeaderHandler extends ScopedHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(HostHeaderHandler.class);
|
||||
|
@ -233,7 +234,7 @@ public class HostHeaderHandler extends ScopedHandler {
|
|||
try {
|
||||
final int lambdaPort = serverPort;
|
||||
List<String> customIPs = extractIPsFromNetworkInterfaces(niFiProperties);
|
||||
customIPs.stream().forEach(ip -> {
|
||||
customIPs.forEach(ip -> {
|
||||
validHosts.add(ip);
|
||||
validHosts.add(ip + ":" + lambdaPort);
|
||||
});
|
||||
|
@ -284,16 +285,20 @@ public class HostHeaderHandler extends ScopedHandler {
|
|||
Map<String, String> networkInterfaces = niFiProperties.isHTTPSConfigured() ? niFiProperties.getHttpsNetworkInterfaces() : niFiProperties.getHttpNetworkInterfaces();
|
||||
if (isNotDefined(networkInterfaces)) {
|
||||
// No custom interfaces defined
|
||||
return new ArrayList<>(0);
|
||||
return List.of();
|
||||
} else {
|
||||
List<String> allIPAddresses = new ArrayList<>();
|
||||
final List<String> allIPAddresses = new ArrayList<>();
|
||||
for (Map.Entry<String, String> entry : networkInterfaces.entrySet()) {
|
||||
final String networkInterfaceName = entry.getValue();
|
||||
try {
|
||||
NetworkInterface ni = NetworkInterface.getByName(networkInterfaceName);
|
||||
List<String> ipAddresses = Collections.list(ni.getInetAddresses()).stream().map(inetAddress -> inetAddress.getHostAddress().toLowerCase()).collect(Collectors.toList());
|
||||
logger.debug("Resolved the following IP addresses for network interface {}: {}", networkInterfaceName, StringUtils.join(ipAddresses, ", "));
|
||||
allIPAddresses.addAll(ipAddresses);
|
||||
final NetworkInterface ni = NetworkInterface.getByName(networkInterfaceName);
|
||||
if (ni == null) {
|
||||
logger.warn("Cannot resolve network interface named " + networkInterfaceName);
|
||||
} else {
|
||||
final List<String> ipAddresses = Collections.list(ni.getInetAddresses()).stream().map(inetAddress -> inetAddress.getHostAddress().toLowerCase()).collect(Collectors.toList());
|
||||
logger.debug("Resolved the following IP addresses for network interface {}: {}", networkInterfaceName, StringUtils.join(ipAddresses, ", "));
|
||||
allIPAddresses.addAll(ipAddresses);
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
logger.warn("Cannot resolve network interface named " + networkInterfaceName);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue