8234147: Avoid looking up standard charsets in core libraries

Reviewed-by: alanb
This commit is contained in:
Ivan Gerasimov 2019-12-01 15:29:37 -08:00
parent 4e64af81a2
commit cd589d8469
36 changed files with 200 additions and 237 deletions

View file

@ -31,7 +31,6 @@ import java.util.Objects;
import java.util.Scanner;
import java.security.AccessController;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.ObjectStreamException;
import java.io.ObjectStreamField;
import java.io.IOException;
@ -52,6 +51,7 @@ import jdk.internal.access.SharedSecrets;
import sun.security.action.*;
import sun.net.InetAddressCachePolicy;
import sun.net.util.IPAddressUtil;
import sun.nio.cs.UTF_8;
/**
* This class represents an Internet Protocol (IP) address.
@ -984,7 +984,9 @@ public class InetAddress implements java.io.Serializable {
String hostEntry;
String host = null;
try (Scanner hostsFileScanner = new Scanner(new File(hostsFile), "UTF-8")) {
try (Scanner hostsFileScanner = new Scanner(new File(hostsFile),
UTF_8.INSTANCE))
{
while (hostsFileScanner.hasNextLine()) {
hostEntry = hostsFileScanner.nextLine();
if (!hostEntry.startsWith("#")) {
@ -997,7 +999,7 @@ public class InetAddress implements java.io.Serializable {
}
}
}
} catch (FileNotFoundException e) {
} catch (IOException e) {
throw new UnknownHostException("Unable to resolve address "
+ Arrays.toString(addr) + " as hosts file " + hostsFile
+ " not found ");
@ -1033,7 +1035,9 @@ public class InetAddress implements java.io.Serializable {
ArrayList<InetAddress> inetAddresses = null;
// lookup the file and create a list InetAddress for the specified host
try (Scanner hostsFileScanner = new Scanner(new File(hostsFile), "UTF-8")) {
try (Scanner hostsFileScanner = new Scanner(new File(hostsFile),
UTF_8.INSTANCE))
{
while (hostsFileScanner.hasNextLine()) {
hostEntry = hostsFileScanner.nextLine();
if (!hostEntry.startsWith("#")) {
@ -1052,7 +1056,7 @@ public class InetAddress implements java.io.Serializable {
}
}
}
} catch (FileNotFoundException e) {
} catch (IOException e) {
throw new UnknownHostException("Unable to resolve host " + host
+ " as hosts file " + hostsFile + " not found ");
}