< prev index next >

src/java.base/share/classes/java/net/InetAddress.java

Print this page
rev 52881 : 8214971: Replace use of string.equals("") with isEmpty()
Reviewed-by: jlaskey, prappo, lancea, dfuchs, redestad

@@ -1007,11 +1007,11 @@
                 throw new UnknownHostException("Unable to resolve address "
                         + addrString + " as hosts file " + hostsFile
                         + " not found ");
             }
 
-            if ((host == null) || (host.equals("")) || (host.equals(" "))) {
+            if ((host == null) || (host.isEmpty()) || (host.equals(" "))) {
                 throw new UnknownHostException("Requested address "
                         + addrString
                         + " resolves to an invalid entry in hosts file "
                         + hostsFile);
             }

@@ -1044,11 +1044,11 @@
                     hostEntry = hostsFileScanner.nextLine();
                     if (!hostEntry.startsWith("#")) {
                         hostEntry = removeComments(hostEntry);
                         if (hostEntry.contains(host)) {
                             addrStr = extractHostAddr(hostEntry, host);
-                            if ((addrStr != null) && (!addrStr.equals(""))) {
+                            if ((addrStr != null) && (!addrStr.isEmpty())) {
                                 addr = createAddressByteArray(addrStr);
                                 if (inetAddresses == null) {
                                     inetAddresses = new ArrayList<>(1);
                                 }
                                 if (addr != null) {
< prev index next >