Skip to content

Commit

Permalink
Fix possible null
Browse files Browse the repository at this point in the history
  • Loading branch information
Xcreen committed Nov 12, 2024
1 parent 2205e6e commit 07428e9
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.xcreen.restsms.server

import java.io.IOException
import java.net.InetAddress
import java.net.NetworkInterface
import java.util.*
import javax.servlet.http.HttpServlet
Expand All @@ -25,12 +24,12 @@ class SMSWelcomeServlet(private val serverLogging: ServerLogging) : HttpServlet(
response.writer.println("Server IP Address: $localIpAddress")
}

private fun getLocalIpAddress(): String {
private fun getLocalIpAddress(): String? {
val networkInterfaces = NetworkInterface.getNetworkInterfaces()
for (interfaceElement in Collections.list(networkInterfaces)) {
val inetAddresses = interfaceElement.inetAddresses
for (inetAddress in Collections.list(inetAddresses)) {
if (!inetAddress.isLoopbackAddress && inetAddress.hostAddress.indexOf(':') == -1) {
if (!inetAddress.isLoopbackAddress && inetAddress?.hostAddress?.indexOf(':') == -1) {
return inetAddress.hostAddress
}
}
Expand Down

0 comments on commit 07428e9

Please sign in to comment.