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

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,8 @@
package com.sun.java.util.jar.pack;
import sun.nio.cs.UTF_8;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
@ -443,7 +445,7 @@ class Driver {
// Skip sig4, disks4, entries4, clen4, coff4, cmt2
i += 4+4+4+4+4+2;
if (i < tail.length)
return new String(tail, i, tail.length-i, "UTF8");
return new String(tail, i, tail.length-i, UTF_8.INSTANCE);
return "";
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,7 +29,7 @@ import sun.security.action.GetBooleanAction;
import static com.sun.security.ntlm.Version.*;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@ -182,13 +182,9 @@ class NTLM {
String readSecurityBuffer(int offset, boolean unicode)
throws NTLMException {
byte[] raw = readSecurityBuffer(offset);
try {
return raw == null ? null : new String(
raw, unicode ? "UnicodeLittleUnmarked" : "ISO8859_1");
} catch (UnsupportedEncodingException ex) {
throw new NTLMException(NTLMException.PACKET_READ_ERROR,
"Invalid input encoding");
}
return raw == null ? null : new String(
raw, unicode ? StandardCharsets.UTF_16LE
: StandardCharsets.ISO_8859_1);
}
}
@ -247,12 +243,9 @@ class NTLM {
}
void writeSecurityBuffer(int offset, String str, boolean unicode) {
try {
writeSecurityBuffer(offset, str == null ? null : str.getBytes(
unicode ? "UnicodeLittleUnmarked" : "ISO8859_1"));
} catch (UnsupportedEncodingException ex) {
assert false;
}
writeSecurityBuffer(offset, str == null ? null : str.getBytes(
unicode ? StandardCharsets.UTF_16LE
: StandardCharsets.ISO_8859_1));
}
byte[] getBytes() {
@ -380,20 +373,14 @@ class NTLM {
}
byte[] calcV2(byte[] nthash, String text, byte[] blob, byte[] challenge) {
try {
byte[] ntlmv2hash = hmacMD5(nthash,
text.getBytes("UnicodeLittleUnmarked"));
byte[] cn = new byte[blob.length+8];
System.arraycopy(challenge, 0, cn, 0, 8);
System.arraycopy(blob, 0, cn, 8, blob.length);
byte[] result = new byte[16+blob.length];
System.arraycopy(hmacMD5(ntlmv2hash, cn), 0, result, 0, 16);
System.arraycopy(blob, 0, result, 16, blob.length);
return result;
} catch (UnsupportedEncodingException ex) {
assert false;
}
return null;
byte[] ntlmv2hash = hmacMD5(nthash, text.getBytes(StandardCharsets.UTF_16LE));
byte[] cn = new byte[blob.length+8];
System.arraycopy(challenge, 0, cn, 0, 8);
System.arraycopy(blob, 0, cn, 8, blob.length);
byte[] result = new byte[16+blob.length];
System.arraycopy(hmacMD5(ntlmv2hash, cn), 0, result, 0, 16);
System.arraycopy(blob, 0, result, 16, blob.length);
return result;
}
// NTLM2 LM/NTLM
@ -412,19 +399,11 @@ class NTLM {
// Password in ASCII and UNICODE
static byte[] getP1(char[] password) {
try {
return new String(password).toUpperCase(
Locale.ENGLISH).getBytes("ISO8859_1");
} catch (UnsupportedEncodingException ex) {
return null;
}
return new String(password).toUpperCase(Locale.ENGLISH)
.getBytes(StandardCharsets.ISO_8859_1);
}
static byte[] getP2(char[] password) {
try {
return new String(password).getBytes("UnicodeLittleUnmarked");
} catch (UnsupportedEncodingException ex) {
return null;
}
return new String(password).getBytes(StandardCharsets.UTF_16LE);
}
}

View File

@ -70,12 +70,8 @@ public class InputStreamReader extends Reader {
*/
public InputStreamReader(InputStream in) {
super(in);
try {
sd = StreamDecoder.forInputStreamReader(in, this, (String)null); // ## check lock object
} catch (UnsupportedEncodingException e) {
// The default encoding should always be available
throw new Error(e);
}
sd = StreamDecoder.forInputStreamReader(in, this,
Charset.defaultCharset()); // ## check lock object
}
/**

View File

@ -106,11 +106,8 @@ public class OutputStreamWriter extends Writer {
*/
public OutputStreamWriter(OutputStream out) {
super(out);
try {
se = StreamEncoder.forOutputStreamWriter(out, this, (String)null);
} catch (UnsupportedEncodingException e) {
throw new Error(e);
}
se = StreamEncoder.forOutputStreamWriter(out, this,
Charset.defaultCharset());
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -151,7 +151,7 @@ class CharacterName {
}
public int getCodePoint(String name) {
byte[] bname = name.getBytes(java.nio.charset.StandardCharsets.ISO_8859_1);
byte[] bname = name.getBytes(sun.nio.cs.ISO_8859_1.INSTANCE);
int hsh = hashN(bname, 0, bname.length);
int idx = hsIndices[(hsh & 0x7fffffff) % hsIndices.length];
while (idx != -1) {

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 ");
}

View File

@ -28,6 +28,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.BufferedOutputStream;
import java.nio.charset.StandardCharsets;
import java.security.AccessController;
import java.util.Iterator;
@ -166,18 +167,10 @@ class SocksSocketImpl extends DelegatingSocketImpl implements SocksConsts {
return false;
out.write(1);
out.write(userName.length());
try {
out.write(userName.getBytes("ISO-8859-1"));
} catch (java.io.UnsupportedEncodingException uee) {
assert false;
}
out.write(userName.getBytes(StandardCharsets.ISO_8859_1));
if (password != null) {
out.write(password.length());
try {
out.write(password.getBytes("ISO-8859-1"));
} catch (java.io.UnsupportedEncodingException uee) {
assert false;
}
out.write(password.getBytes(StandardCharsets.ISO_8859_1));
} else
out.write(0);
out.flush();
@ -208,11 +201,7 @@ class SocksSocketImpl extends DelegatingSocketImpl implements SocksConsts {
out.write((endpoint.getPort() >> 0) & 0xff);
out.write(endpoint.getAddress().getAddress());
String userName = getUserName();
try {
out.write(userName.getBytes("ISO-8859-1"));
} catch (java.io.UnsupportedEncodingException uee) {
assert false;
}
out.write(userName.getBytes(StandardCharsets.ISO_8859_1));
out.write(0);
out.flush();
byte[] data = new byte[8];
@ -427,11 +416,7 @@ class SocksSocketImpl extends DelegatingSocketImpl implements SocksConsts {
if (epoint.isUnresolved()) {
out.write(DOMAIN_NAME);
out.write(epoint.getHostName().length());
try {
out.write(epoint.getHostName().getBytes("ISO-8859-1"));
} catch (java.io.UnsupportedEncodingException uee) {
assert false;
}
out.write(epoint.getHostName().getBytes(StandardCharsets.ISO_8859_1));
out.write((epoint.getPort() >> 8) & 0xff);
out.write((epoint.getPort() >> 0) & 0xff);
} else if (epoint.getAddress() instanceof Inet6Address) {

View File

@ -42,11 +42,11 @@ import java.text.Normalizer;
import jdk.internal.access.JavaNetUriAccess;
import jdk.internal.access.SharedSecrets;
import sun.nio.cs.ThreadLocalCoders;
import sun.nio.cs.UTF_8;
import java.lang.Character; // for javadoc
import java.lang.NullPointerException; // for javadoc
/**
* Represents a Uniform Resource Identifier (URI) reference.
*
@ -2739,7 +2739,7 @@ public final class URI
private static void appendEncoded(StringBuilder sb, char c) {
ByteBuffer bb = null;
try {
bb = ThreadLocalCoders.encoderFor("UTF-8")
bb = ThreadLocalCoders.encoderFor(UTF_8.INSTANCE)
.encode(CharBuffer.wrap("" + c));
} catch (CharacterCodingException x) {
assert false;
@ -2807,7 +2807,7 @@ public final class URI
String ns = Normalizer.normalize(s, Normalizer.Form.NFC);
ByteBuffer bb = null;
try {
bb = ThreadLocalCoders.encoderFor("UTF-8")
bb = ThreadLocalCoders.encoderFor(UTF_8.INSTANCE)
.encode(CharBuffer.wrap(ns));
} catch (CharacterCodingException x) {
assert false;
@ -2865,7 +2865,7 @@ public final class URI
StringBuilder sb = new StringBuilder(n);
ByteBuffer bb = ByteBuffer.allocate(n);
CharBuffer cb = CharBuffer.allocate(n);
CharsetDecoder dec = ThreadLocalCoders.decoderFor("UTF-8")
CharsetDecoder dec = ThreadLocalCoders.decoderFor(UTF_8.INSTANCE)
.onMalformedInput(CodingErrorAction.REPLACE)
.onUnmappableCharacter(CodingErrorAction.REPLACE);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,6 +24,10 @@
*/
package java.nio.file;
import sun.nio.cs.ISO_8859_1;
import sun.nio.cs.UTF_8;
import sun.nio.cs.US_ASCII;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.UncheckedIOException;
@ -32,7 +36,6 @@ import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;
import java.util.Spliterator;
@ -66,9 +69,9 @@ final class FileChannelLinesSpliterator implements Spliterator<String> {
static final Set<String> SUPPORTED_CHARSET_NAMES;
static {
SUPPORTED_CHARSET_NAMES = new HashSet<>();
SUPPORTED_CHARSET_NAMES.add(StandardCharsets.UTF_8.name());
SUPPORTED_CHARSET_NAMES.add(StandardCharsets.ISO_8859_1.name());
SUPPORTED_CHARSET_NAMES.add(StandardCharsets.US_ASCII.name());
SUPPORTED_CHARSET_NAMES.add(UTF_8.INSTANCE.name());
SUPPORTED_CHARSET_NAMES.add(ISO_8859_1.INSTANCE.name());
SUPPORTED_CHARSET_NAMES.add(US_ASCII.INSTANCE.name());
}
private final FileChannel fc;

View File

@ -79,6 +79,7 @@ import java.util.stream.StreamSupport;
import jdk.internal.util.ArraysSupport;
import sun.nio.ch.FileChannelImpl;
import sun.nio.cs.UTF_8;
import sun.nio.fs.AbstractFileSystemProvider;
/**
@ -2944,7 +2945,7 @@ public final class Files {
* @since 1.8
*/
public static BufferedReader newBufferedReader(Path path) throws IOException {
return newBufferedReader(path, StandardCharsets.UTF_8);
return newBufferedReader(path, UTF_8.INSTANCE);
}
/**
@ -3036,7 +3037,7 @@ public final class Files {
public static BufferedWriter newBufferedWriter(Path path, OpenOption... options)
throws IOException
{
return newBufferedWriter(path, StandardCharsets.UTF_8, options);
return newBufferedWriter(path, UTF_8.INSTANCE, options);
}
/**
@ -3305,7 +3306,7 @@ public final class Files {
* @since 11
*/
public static String readString(Path path) throws IOException {
return readString(path, StandardCharsets.UTF_8);
return readString(path, UTF_8.INSTANCE);
}
/**
@ -3430,7 +3431,7 @@ public final class Files {
* @since 1.8
*/
public static List<String> readAllLines(Path path) throws IOException {
return readAllLines(path, StandardCharsets.UTF_8);
return readAllLines(path, UTF_8.INSTANCE);
}
/**
@ -3601,7 +3602,7 @@ public final class Files {
OpenOption... options)
throws IOException
{
return write(path, lines, StandardCharsets.UTF_8, options);
return write(path, lines, UTF_8.INSTANCE, options);
}
/**
@ -3641,7 +3642,7 @@ public final class Files {
public static Path writeString(Path path, CharSequence csq, OpenOption... options)
throws IOException
{
return writeString(path, csq, StandardCharsets.UTF_8, options);
return writeString(path, csq, UTF_8.INSTANCE, options);
}
/**
@ -4188,6 +4189,6 @@ public final class Files {
* @since 1.8
*/
public static Stream<String> lines(Path path) throws IOException {
return lines(path, StandardCharsets.UTF_8);
return lines(path, UTF_8.INSTANCE);
}
}

View File

@ -31,6 +31,9 @@ import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import sun.nio.cs.ISO_8859_1;
import jdk.internal.HotSpotIntrinsicCandidate;
/**
@ -584,7 +587,7 @@ public class Base64 {
* if {@code src} is not in valid Base64 scheme
*/
public byte[] decode(String src) {
return decode(src.getBytes(StandardCharsets.ISO_8859_1));
return decode(src.getBytes(ISO_8859_1.INSTANCE));
}
/**

View File

@ -46,6 +46,9 @@ import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
import sun.nio.cs.ISO_8859_1;
import sun.nio.cs.UTF_8;
import jdk.internal.access.SharedSecrets;
import jdk.internal.misc.Unsafe;
import jdk.internal.util.ArraysSupport;
@ -909,7 +912,7 @@ public class Properties extends Hashtable<Object,Object> {
public void store(OutputStream out, String comments)
throws IOException
{
store0(new BufferedWriter(new OutputStreamWriter(out, "8859_1")),
store0(new BufferedWriter(new OutputStreamWriter(out, ISO_8859_1.INSTANCE)),
comments,
true);
}
@ -1001,7 +1004,7 @@ public class Properties extends Hashtable<Object,Object> {
public void storeToXML(OutputStream os, String comment)
throws IOException
{
storeToXML(os, comment, "UTF-8");
storeToXML(os, comment, UTF_8.INSTANCE);
}
/**

View File

@ -44,8 +44,8 @@ import java.io.InputStreamReader;
import java.io.Reader;
import java.io.IOException;
import java.nio.charset.MalformedInputException;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnmappableCharacterException;
import sun.nio.cs.ISO_8859_1;
import sun.security.action.GetPropertyAction;
import sun.util.PropertyResourceBundleCharset;
import sun.util.ResourceBundleEnumeration;
@ -176,7 +176,7 @@ public class PropertyResourceBundle extends ResourceBundle {
public PropertyResourceBundle (InputStream stream) throws IOException {
this(new InputStreamReader(stream,
"ISO-8859-1".equals(encoding) ?
StandardCharsets.ISO_8859_1.newDecoder() :
ISO_8859_1.INSTANCE.newDecoder() :
new PropertyResourceBundleCharset("UTF-8".equals(encoding)).newDecoder()));
}

View File

@ -45,6 +45,8 @@ import java.util.function.Supplier;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import sun.nio.cs.UTF_8;
import jdk.internal.loader.BootLoader;
import jdk.internal.loader.ClassLoaders;
import jdk.internal.access.JavaLangAccess;
@ -55,7 +57,6 @@ import jdk.internal.module.ServicesCatalog.ServiceProvider;
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection;
/**
* A facility to load implementations of a service.
*
@ -1164,7 +1165,7 @@ public final class ServiceLoader<S>
uc.setUseCaches(false);
try (InputStream in = uc.getInputStream();
BufferedReader r
= new BufferedReader(new InputStreamReader(in, "utf-8")))
= new BufferedReader(new InputStreamReader(in, UTF_8.INSTANCE)))
{
int lc = 1;
while ((lc = parseLine(u, r, lc, names)) >= 0);

View File

@ -36,9 +36,9 @@ import java.util.Set;
import jdk.internal.misc.VM;
import jdk.internal.vm.annotation.Stable;
import sun.util.logging.PlatformLogger;
import static java.nio.charset.StandardCharsets.UTF_8;
import sun.nio.cs.UTF_8;
import sun.util.logging.PlatformLogger;
/**
* The Attributes class maps Manifest attribute names to associated string
@ -337,7 +337,7 @@ public class Attributes implements Map<Object,Object>, Cloneable {
buffer.append(vername);
buffer.append(": ");
buffer.append(version);
out.write(buffer.toString().getBytes(UTF_8));
out.write(buffer.toString().getBytes(UTF_8.INSTANCE));
Manifest.println(out);
}
@ -399,7 +399,7 @@ public class Attributes implements Map<Object,Object>, Cloneable {
lastline = buf;
continue;
}
value = new String(buf, 0, buf.length, UTF_8);
value = new String(buf, 0, buf.length, UTF_8.INSTANCE);
lastline = null;
} else {
while (lbuf[i++] != ':') {
@ -412,13 +412,13 @@ public class Attributes implements Map<Object,Object>, Cloneable {
throw new IOException("invalid header field ("
+ Manifest.getErrorPosition(filename, lineNumber) + ")");
}
name = new String(lbuf, 0, i - 2, UTF_8);
name = new String(lbuf, 0, i - 2, UTF_8.INSTANCE);
if (is.peek() == ' ') {
lastline = new byte[len - i];
System.arraycopy(lbuf, i, lastline, 0, len - i);
continue;
}
value = new String(lbuf, i, len - i, UTF_8);
value = new String(lbuf, i, len - i, UTF_8.INSTANCE);
}
try {
if ((putValue(name, value) != null) && (!lineContinued)) {

View File

@ -33,10 +33,9 @@ import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import sun.nio.cs.UTF_8;
import sun.security.util.SecurityProperties;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* The Manifest class is used to maintain Manifest entry names and their
* associated Attributes. There are main Manifest Attributes as well as
@ -237,7 +236,7 @@ public class Manifest implements Cloneable {
*/
static void println72(OutputStream out, String line) throws IOException {
if (!line.isEmpty()) {
byte[] lineBytes = line.getBytes(UTF_8);
byte[] lineBytes = line.getBytes(UTF_8.INSTANCE);
int length = lineBytes.length;
// first line can hold one byte more than subsequent lines which
// start with a continuation line break space
@ -337,7 +336,7 @@ public class Manifest implements Cloneable {
lastline = buf;
continue;
}
name = new String(buf, 0, buf.length, UTF_8);
name = new String(buf, 0, buf.length, UTF_8.INSTANCE);
lastline = null;
}
Attributes attr = getAttributes(name);
@ -362,11 +361,7 @@ public class Manifest implements Cloneable {
if (toLower(lbuf[0]) == 'n' && toLower(lbuf[1]) == 'a' &&
toLower(lbuf[2]) == 'm' && toLower(lbuf[3]) == 'e' &&
lbuf[4] == ':' && lbuf[5] == ' ') {
try {
return new String(lbuf, 6, len - 6, UTF_8);
}
catch (Exception e) {
}
return new String(lbuf, 6, len - 6, UTF_8.INSTANCE);
}
return null;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -33,7 +33,7 @@ import java.nio.charset.CharsetEncoder;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CodingErrorAction;
import static java.nio.charset.StandardCharsets.UTF_8;
import sun.nio.cs.UTF_8;
/**
* Utility class for zipfile name and comment decoding and encoding
@ -67,10 +67,10 @@ class ZipCoder {
}
// UTF_8.ArrayEn/Decoder is stateless, so make it singleton.
private static ZipCoder utf8 = new UTF8(UTF_8);
private static ZipCoder utf8 = new UTF8(UTF_8.INSTANCE);
public static ZipCoder get(Charset charset) {
if (charset == UTF_8)
if (charset == UTF_8.INSTANCE)
return utf8;
return new ZipCoder(charset);
}

View File

@ -34,7 +34,6 @@ import java.io.RandomAccessFile;
import java.io.UncheckedIOException;
import java.lang.ref.Cleaner.Cleanable;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.InvalidPathException;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.Files;
@ -65,6 +64,7 @@ import jdk.internal.misc.VM;
import jdk.internal.perf.PerfCounter;
import jdk.internal.ref.CleanerFactory;
import jdk.internal.vm.annotation.Stable;
import sun.nio.cs.UTF_8;
import static java.util.zip.ZipConstants64.*;
import static java.util.zip.ZipUtils.*;
@ -165,7 +165,7 @@ public class ZipFile implements ZipConstants, Closeable {
* @since 1.3
*/
public ZipFile(File file, int mode) throws IOException {
this(file, mode, StandardCharsets.UTF_8);
this(file, mode, UTF_8.INSTANCE);
}
/**
@ -1042,7 +1042,7 @@ public class ZipFile implements ZipConstants, Closeable {
for (int i = 0; i < names.length; i++) {
int pos = zsrc.metanames[i];
names[i] = new String(cen, pos + CENHDR, CENNAM(cen, pos),
StandardCharsets.UTF_8);
UTF_8.INSTANCE);
}
return names;
}

View File

@ -30,7 +30,9 @@ import java.io.IOException;
import java.io.EOFException;
import java.io.PushbackInputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import sun.nio.cs.UTF_8;
import static java.util.zip.ZipConstants64.*;
import static java.util.zip.ZipUtils.*;
@ -77,7 +79,7 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
* @param in the actual input stream
*/
public ZipInputStream(InputStream in) {
this(in, StandardCharsets.UTF_8);
this(in, UTF_8.INSTANCE);
}
/**

View File

@ -28,11 +28,11 @@ package java.util.zip;
import java.io.OutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Vector;
import java.util.HashSet;
import static java.util.zip.ZipConstants64.*;
import static java.util.zip.ZipUtils.*;
import sun.nio.cs.UTF_8;
import sun.security.action.GetPropertyAction;
/**
@ -116,7 +116,7 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
* @param out the actual output stream
*/
public ZipOutputStream(OutputStream out) {
this(out, StandardCharsets.UTF_8);
this(out, UTF_8.INSTANCE);
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,6 +24,8 @@
*/
package jdk.internal.module;
import sun.nio.cs.UTF_8;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@ -37,8 +39,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import static java.nio.charset.StandardCharsets.*;
/**
* Generates the maps of concealed and exported packages to open at run-time.
*
@ -90,7 +90,9 @@ public class IllegalAccessMaps {
if (in == null) {
throw new InternalError(rn + " not found");
}
try (BufferedReader br = new BufferedReader(new InputStreamReader(in, UTF_8))) {
try (BufferedReader br = new BufferedReader(
new InputStreamReader(in, UTF_8.INSTANCE)))
{
br.lines()
.filter(line -> !line.isEmpty() && !line.startsWith("#"))
.forEach(pn -> {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -61,6 +61,8 @@ import java.util.stream.Collectors;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import sun.nio.cs.UTF_8;
import jdk.internal.jmod.JmodFile;
import jdk.internal.jmod.JmodFile.Section;
import jdk.internal.perf.PerfCounter;
@ -543,7 +545,7 @@ public class ModulePath implements ModuleFinder {
List<String> providerClasses = new ArrayList<>();
try (InputStream in = jf.getInputStream(entry)) {
BufferedReader reader
= new BufferedReader(new InputStreamReader(in, "UTF-8"));
= new BufferedReader(new InputStreamReader(in, UTF_8.INSTANCE));
String cn;
while ((cn = nextLine(reader)) != null) {
if (!cn.isEmpty()) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,9 @@ import java.nio.ByteBuffer;
import java.security.Permission;
import java.security.PrivilegedAction;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import sun.nio.cs.UTF_8;
import jdk.internal.ref.CleanerFactory;
/**
@ -413,7 +415,7 @@ public final class Perf {
public ByteBuffer createString(String name, int variability,
int units, String value, int maxLength)
{
byte[] v = getBytes(value);
byte[] v = value.getBytes(UTF_8.INSTANCE);
byte[] v1 = new byte[v.length+1];
System.arraycopy(v, 0, v1, 0, v.length);
v1[v.length] = '\0';
@ -452,7 +454,7 @@ public final class Perf {
public ByteBuffer createString(String name, int variability,
int units, String value)
{
byte[] v = getBytes(value);
byte[] v = value.getBytes(UTF_8.INSTANCE);
byte[] v1 = new byte[v.length+1];
System.arraycopy(v, 0, v1, 0, v.length);
v1[v.length] = '\0';
@ -491,24 +493,6 @@ public final class Perf {
int units, byte[] value,
int maxLength);
/**
* convert string to an array of UTF-8 bytes
*/
private static byte[] getBytes(String s)
{
byte[] bytes = null;
try {
bytes = s.getBytes("UTF-8");
}
catch (UnsupportedEncodingException e) {
// ignore, UTF-8 encoding is always known
}
return bytes;
}
/**
* Return the value of the High Resolution Counter.
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,10 +25,13 @@
package jdk.internal.util.jar;
import sun.nio.cs.UTF_8;
import java.io.*;
import java.util.*;
import java.util.jar.*;
import java.util.zip.*;
import static sun.security.action.GetPropertyAction.privilegedGetProperty;
/**
@ -250,7 +253,7 @@ public class JarIndex {
*/
public void write(OutputStream out) throws IOException {
BufferedWriter bw = new BufferedWriter
(new OutputStreamWriter(out, "UTF8"));
(new OutputStreamWriter(out, UTF_8.INSTANCE));
bw.write("JarIndex-Version: 1.0\n\n");
if (jarFiles != null) {
@ -280,7 +283,7 @@ public class JarIndex {
*/
public void read(InputStream is) throws IOException {
BufferedReader br = new BufferedReader
(new InputStreamReader(is, "UTF8"));
(new InputStreamReader(is, UTF_8.INSTANCE));
String line = null;
String currentJar = null;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,19 +26,20 @@
package sun.net.www;
import java.io.File;
import java.net.URL;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import sun.nio.cs.ThreadLocalCoders;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CoderResult;
import java.nio.charset.CodingErrorAction;
import sun.nio.cs.ThreadLocalCoders;
import sun.nio.cs.UTF_8;
/**
* A class that contains useful routines common to sun.net.www
* @author Mike McCloskey
@ -176,7 +177,7 @@ public final class ParseUtil {
StringBuilder sb = new StringBuilder(n);
ByteBuffer bb = ByteBuffer.allocate(n);
CharBuffer cb = CharBuffer.allocate(n);
CharsetDecoder dec = ThreadLocalCoders.decoderFor("UTF-8")
CharsetDecoder dec = ThreadLocalCoders.decoderFor(UTF_8.INSTANCE)
.onMalformedInput(CodingErrorAction.REPORT)
.onUnmappableCharacter(CodingErrorAction.REPORT);
@ -496,7 +497,7 @@ public final class ParseUtil {
private static void appendEncoded(StringBuilder sb, char c) {
ByteBuffer bb = null;
try {
bb = ThreadLocalCoders.encoderFor("UTF-8")
bb = ThreadLocalCoders.encoderFor(UTF_8.INSTANCE)
.encode(CharBuffer.wrap("" + c));
} catch (CharacterCodingException x) {
assert false;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,6 +29,7 @@ import java.util.*;
import sun.net.*;
import sun.net.www.*;
import sun.nio.cs.US_ASCII;
/**
* A <code>ChunkedInputStream</code> provides a stream for reading a body of
@ -307,7 +308,8 @@ class ChunkedInputStream extends InputStream implements Hurryable {
/*
* Extract the chunk size from the header (ignoring extensions).
*/
String header = new String(rawData, rawPos, pos-rawPos+1, "US-ASCII");
String header = new String(rawData, rawPos, pos-rawPos+1,
US_ASCII.INSTANCE);
for (i=0; i < header.length(); i++) {
if (Character.digit(header.charAt(i), 16) == -1)
break;
@ -461,7 +463,8 @@ class ChunkedInputStream extends InputStream implements Hurryable {
* Extract any tailers and append them to the message
* headers.
*/
String trailer = new String(rawData, rawPos, pos-rawPos, "US-ASCII");
String trailer = new String(rawData, rawPos, pos-rawPos,
US_ASCII.INSTANCE);
i = trailer.indexOf(':');
if (i == -1) {
throw new IOException("Malformed tailer - format should be key:value");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,6 +26,8 @@ package sun.net.www.http;
import java.io.*;
import sun.nio.cs.US_ASCII;
/**
* OutputStream that sends the output to the underlying stream using chunked
* encoding as specified in RFC 2068.
@ -67,20 +69,15 @@ public class ChunkedOutputStream extends PrintStream {
}
/* return a header for a particular chunk size */
private static byte[] getHeader(int size){
try {
String hexStr = Integer.toHexString(size);
byte[] hexBytes = hexStr.getBytes("US-ASCII");
byte[] header = new byte[getHeaderSize(size)];
for (int i=0; i<hexBytes.length; i++)
header[i] = hexBytes[i];
header[hexBytes.length] = CRLF[0];
header[hexBytes.length+1] = CRLF[1];
return header;
} catch (java.io.UnsupportedEncodingException e) {
/* This should never happen */
throw new InternalError(e.getMessage(), e);
}
private static byte[] getHeader(int size) {
String hexStr = Integer.toHexString(size);
byte[] hexBytes = hexStr.getBytes(US_ASCII.INSTANCE);
byte[] header = new byte[getHeaderSize(size)];
for (int i=0; i<hexBytes.length; i++)
header[i] = hexBytes[i];
header[hexBytes.length] = CRLF[0];
header[hexBytes.length+1] = CRLF[1];
return header;
}
public ChunkedOutputStream(PrintStream o) {

View File

@ -38,8 +38,8 @@ import java.util.Arrays;
import java.util.Base64;
import java.util.Objects;
import sun.net.www.HeaderParser;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import sun.nio.cs.ISO_8859_1;
import sun.nio.cs.UTF_8;
/**
* BasicAuthentication: Encapsulate an http server authentication using
@ -101,10 +101,11 @@ class BasicAuthentication extends AuthenticationInfo {
char[] password = pw.getPassword();
CharBuffer cbuf = CharBuffer.allocate(plain.length() + password.length);
cbuf.put(plain).put(password).flip();
Charset charset = isUTF8 ? UTF_8 : ISO_8859_1;
Charset charset = isUTF8 ? UTF_8.INSTANCE : ISO_8859_1.INSTANCE;
ByteBuffer buf = charset.encode(cbuf);
ByteBuffer enc = Base64.getEncoder().encode(buf);
String ret = "Basic " + new String(enc.array(), enc.position(), enc.remaining(), ISO_8859_1);
String ret = "Basic " + new String(enc.array(), enc.position(), enc.remaining(),
ISO_8859_1.INSTANCE);
Arrays.fill(buf.array(), (byte) 0);
Arrays.fill(enc.array(), (byte) 0);
Arrays.fill(cbuf.array(), (char) 0);

View File

@ -26,19 +26,21 @@
package sun.net.www.protocol.http;
import java.io.*;
import java.net.URL;
import java.net.ProtocolException;
import java.net.PasswordAuthentication;
import java.util.Arrays;
import java.util.Random;
import sun.net.www.HeaderParser;
import sun.net.NetProperties;
import java.net.ProtocolException;
import java.net.URL;
import java.security.AccessController;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivilegedAction;
import java.security.AccessController;
import java.util.Arrays;
import java.util.Objects;
import java.util.Random;
import sun.net.NetProperties;
import sun.net.www.HeaderParser;
import sun.nio.cs.ISO_8859_1;
import static sun.net.www.protocol.http.HttpURLConnection.HTTP_CONNECT;
/**
@ -521,11 +523,7 @@ class DigestAuthentication extends AuthenticationInfo {
};
private String encode(String src, char[] passwd, MessageDigest md) {
try {
md.update(src.getBytes("ISO-8859-1"));
} catch (java.io.UnsupportedEncodingException uee) {
assert false;
}
md.update(src.getBytes(ISO_8859_1.INSTANCE));
if (passwd != null) {
byte[] passwdBytes = new byte[passwd.length];
for (int i=0; i<passwd.length; i++)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -87,17 +87,17 @@ public class ThreadLocalCoders {
private static Cache decoderCache = new Cache(CACHE_SIZE) {
boolean hasName(Object ob, Object name) {
if (name instanceof String)
return (((CharsetDecoder)ob).charset().name().equals(name));
if (name instanceof Charset)
return ((CharsetDecoder)ob).charset().equals(name);
if (name instanceof String)
return (((CharsetDecoder)ob).charset().name().equals(name));
return false;
}
Object create(Object name) {
if (name instanceof String)
return Charset.forName((String)name).newDecoder();
if (name instanceof Charset)
return ((Charset)name).newDecoder();
if (name instanceof String)
return Charset.forName((String)name).newDecoder();
assert false;
return null;
}
@ -111,17 +111,17 @@ public class ThreadLocalCoders {
private static Cache encoderCache = new Cache(CACHE_SIZE) {
boolean hasName(Object ob, Object name) {
if (name instanceof String)
return (((CharsetEncoder)ob).charset().name().equals(name));
if (name instanceof Charset)
return ((CharsetEncoder)ob).charset().equals(name);
if (name instanceof String)
return (((CharsetEncoder)ob).charset().name().equals(name));
return false;
}
Object create(Object name) {
if (name instanceof String)
return Charset.forName((String)name).newEncoder();
if (name instanceof Charset)
return ((Charset)name).newEncoder();
if (name instanceof String)
return Charset.forName((String)name).newEncoder();
assert false;
return null;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,9 @@
package sun.util;
import sun.nio.cs.ISO_8859_1;
import sun.nio.cs.UTF_8;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
@ -70,7 +73,7 @@ public class PropertyResourceBundleCharset extends Charset {
private final class PropertiesFileDecoder extends CharsetDecoder {
private CharsetDecoder cdUTF_8 = StandardCharsets.UTF_8.newDecoder()
private CharsetDecoder cdUTF_8 = UTF_8.INSTANCE.newDecoder()
.onMalformedInput(CodingErrorAction.REPORT)
.onUnmappableCharacter(CodingErrorAction.REPORT);
private CharsetDecoder cdISO_8859_1 = null;
@ -98,7 +101,7 @@ public class PropertyResourceBundleCharset extends Charset {
assert cr.isMalformed() || cr.isUnmappable();
in.reset();
out.reset();
cdISO_8859_1 = StandardCharsets.ISO_8859_1.newDecoder();
cdISO_8859_1 = ISO_8859_1.INSTANCE.newDecoder();
return cdISO_8859_1.decode(in, out, false);
}
}

View File

@ -25,6 +25,8 @@
package sun.nio.fs;
import sun.nio.cs.UTF_8;
import jdk.internal.util.StaticProperty;
import java.nio.file.*;
@ -277,7 +279,7 @@ abstract class UnixFileStore
Path file = Path.of(fstypes);
try {
try (ReadableByteChannel rbc = Files.newByteChannel(file)) {
result.load(Channels.newReader(rbc, "UTF-8"));
result.load(Channels.newReader(rbc, UTF_8.INSTANCE));
}
} catch (IOException x) {
}

View File

@ -39,7 +39,6 @@ import java.io.Closeable;
import java.io.IOException;
import java.io.PrintStream;
import java.io.UncheckedIOException;
import java.io.UnsupportedEncodingException;
import java.lang.System.Logger.Level;
import java.net.ConnectException;
import java.net.InetSocketAddress;
@ -74,6 +73,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.util.stream.Collectors.joining;
import jdk.internal.net.http.HttpRequestImpl;
@ -538,15 +538,9 @@ public final class Utils {
public static String stackTrace(Throwable t) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
String s = null;
try {
PrintStream p = new PrintStream(bos, true, "US-ASCII");
t.printStackTrace(p);
s = bos.toString("US-ASCII");
} catch (UnsupportedEncodingException ex) {
throw new InternalError(ex); // Can't happen
}
return s;
PrintStream p = new PrintStream(bos, true, US_ASCII);
t.printStackTrace(p);
return bos.toString(US_ASCII);
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -34,6 +34,8 @@ import javax.xml.transform.stream.*;
import org.xml.sax.*;
import org.w3c.dom.*;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* XML Support for java.util.prefs. Methods to import and export preference
* nodes and subtrees.
@ -274,7 +276,7 @@ class XmlSupport {
//an OutputStream object embedded, creating a Writer object on top of that
//OutputStream object however works.
t.transform(new DOMSource(doc),
new StreamResult(new BufferedWriter(new OutputStreamWriter(out, "UTF-8"))));
new StreamResult(new BufferedWriter(new OutputStreamWriter(out, UTF_8))));
} catch(TransformerException e) {
throw new AssertionError(e);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -42,6 +42,8 @@ import com.sun.rowset.internal.*;
import com.sun.rowset.providers.*;
import sun.reflect.misc.ReflectUtil;
import static java.nio.charset.StandardCharsets.US_ASCII;
/**
* The standard implementation of the <code>CachedRowSet</code> interface.
*
@ -2348,14 +2350,10 @@ public class CachedRowSetImpl extends BaseRowSet implements RowSet, RowSetIntern
return null;
}
try {
if (isString(RowSetMD.getColumnType(columnIndex))) {
asciiStream = new ByteArrayInputStream(((String)value).getBytes("ASCII"));
} else {
throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString());
}
} catch (java.io.UnsupportedEncodingException ex) {
throw new SQLException(ex.getMessage());
if (isString(RowSetMD.getColumnType(columnIndex))) {
asciiStream = new ByteArrayInputStream(((String)value).getBytes(US_ASCII));
} else {
throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString());
}
return asciiStream;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
* @test
* @build TrySetAccessibleTest
* @modules java.base/java.lang:open
* java.base/jdk.internal.module
* java.base/jdk.internal.perf
* java.base/jdk.internal.misc:+open
* @run testng/othervm --illegal-access=deny TrySetAccessibleTest
@ -38,6 +39,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import jdk.internal.misc.Unsafe;
import jdk.internal.module.ModulePath;
import jdk.internal.perf.Perf;
import org.testng.annotations.Test;
@ -80,7 +82,7 @@ public class TrySetAccessibleTest {
* Invoke a private method on a public class in an exported package
*/
public void testPrivateMethodInExportedPackage() throws Exception {
Method m = Perf.class.getDeclaredMethod("getBytes", String.class);
Method m = ModulePath.class.getDeclaredMethod("packageName", String.class);
try {
m.invoke(null);
assertTrue(false);