Skip to content

Commit 7259df2

Browse files
committed
Merging master HEAD into openj9-staging
2 parents 96b8d5b + d1e01a1 commit 7259df2

File tree

36 files changed

+200
-237
lines changed

36 files changed

+200
-237
lines changed

src/java.base/share/classes/com/sun/java/util/jar/pack/Driver.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
2525

2626
package com.sun.java.util.jar.pack;
2727

28+
import sun.nio.cs.UTF_8;
29+
2830
import java.io.BufferedInputStream;
2931
import java.io.BufferedOutputStream;
3032
import java.io.File;
@@ -443,7 +445,7 @@ String getZipComment(String jarfile) throws IOException {
443445
// Skip sig4, disks4, entries4, clen4, coff4, cmt2
444446
i += 4+4+4+4+4+2;
445447
if (i < tail.length)
446-
return new String(tail, i, tail.length-i, "UTF8");
448+
return new String(tail, i, tail.length-i, UTF_8.INSTANCE);
447449
return "";
448450
}
449451
}

src/java.base/share/classes/com/sun/security/ntlm/NTLM.java

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,7 +29,7 @@
2929

3030
import static com.sun.security.ntlm.Version.*;
3131
import java.io.IOException;
32-
import java.io.UnsupportedEncodingException;
32+
import java.nio.charset.StandardCharsets;
3333
import java.security.InvalidKeyException;
3434
import java.security.MessageDigest;
3535
import java.security.NoSuchAlgorithmException;
@@ -182,13 +182,9 @@ byte[] readSecurityBuffer(int offset) throws NTLMException {
182182
String readSecurityBuffer(int offset, boolean unicode)
183183
throws NTLMException {
184184
byte[] raw = readSecurityBuffer(offset);
185-
try {
186-
return raw == null ? null : new String(
187-
raw, unicode ? "UnicodeLittleUnmarked" : "ISO8859_1");
188-
} catch (UnsupportedEncodingException ex) {
189-
throw new NTLMException(NTLMException.PACKET_READ_ERROR,
190-
"Invalid input encoding");
191-
}
185+
return raw == null ? null : new String(
186+
raw, unicode ? StandardCharsets.UTF_16LE
187+
: StandardCharsets.ISO_8859_1);
192188
}
193189
}
194190

@@ -247,12 +243,9 @@ void writeSecurityBuffer(int offset, byte[] data) {
247243
}
248244

249245
void writeSecurityBuffer(int offset, String str, boolean unicode) {
250-
try {
251-
writeSecurityBuffer(offset, str == null ? null : str.getBytes(
252-
unicode ? "UnicodeLittleUnmarked" : "ISO8859_1"));
253-
} catch (UnsupportedEncodingException ex) {
254-
assert false;
255-
}
246+
writeSecurityBuffer(offset, str == null ? null : str.getBytes(
247+
unicode ? StandardCharsets.UTF_16LE
248+
: StandardCharsets.ISO_8859_1));
256249
}
257250

258251
byte[] getBytes() {
@@ -380,20 +373,14 @@ byte[] hmacMD5(byte[] key, byte[] text) {
380373
}
381374

382375
byte[] calcV2(byte[] nthash, String text, byte[] blob, byte[] challenge) {
383-
try {
384-
byte[] ntlmv2hash = hmacMD5(nthash,
385-
text.getBytes("UnicodeLittleUnmarked"));
386-
byte[] cn = new byte[blob.length+8];
387-
System.arraycopy(challenge, 0, cn, 0, 8);
388-
System.arraycopy(blob, 0, cn, 8, blob.length);
389-
byte[] result = new byte[16+blob.length];
390-
System.arraycopy(hmacMD5(ntlmv2hash, cn), 0, result, 0, 16);
391-
System.arraycopy(blob, 0, result, 16, blob.length);
392-
return result;
393-
} catch (UnsupportedEncodingException ex) {
394-
assert false;
395-
}
396-
return null;
376+
byte[] ntlmv2hash = hmacMD5(nthash, text.getBytes(StandardCharsets.UTF_16LE));
377+
byte[] cn = new byte[blob.length+8];
378+
System.arraycopy(challenge, 0, cn, 0, 8);
379+
System.arraycopy(blob, 0, cn, 8, blob.length);
380+
byte[] result = new byte[16+blob.length];
381+
System.arraycopy(hmacMD5(ntlmv2hash, cn), 0, result, 0, 16);
382+
System.arraycopy(blob, 0, result, 16, blob.length);
383+
return result;
397384
}
398385

399386
// NTLM2 LM/NTLM
@@ -412,19 +399,11 @@ byte[] ntlm2NTLM(byte[] ntlmHash, byte[] nonce, byte[] challenge) {
412399
// Password in ASCII and UNICODE
413400

414401
static byte[] getP1(char[] password) {
415-
try {
416-
return new String(password).toUpperCase(
417-
Locale.ENGLISH).getBytes("ISO8859_1");
418-
} catch (UnsupportedEncodingException ex) {
419-
return null;
420-
}
402+
return new String(password).toUpperCase(Locale.ENGLISH)
403+
.getBytes(StandardCharsets.ISO_8859_1);
421404
}
422405

423406
static byte[] getP2(char[] password) {
424-
try {
425-
return new String(password).getBytes("UnicodeLittleUnmarked");
426-
} catch (UnsupportedEncodingException ex) {
427-
return null;
428-
}
407+
return new String(password).getBytes(StandardCharsets.UTF_16LE);
429408
}
430409
}

src/java.base/share/classes/java/io/InputStreamReader.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,8 @@ public class InputStreamReader extends Reader {
7070
*/
7171
public InputStreamReader(InputStream in) {
7272
super(in);
73-
try {
74-
sd = StreamDecoder.forInputStreamReader(in, this, (String)null); // ## check lock object
75-
} catch (UnsupportedEncodingException e) {
76-
// The default encoding should always be available
77-
throw new Error(e);
78-
}
73+
sd = StreamDecoder.forInputStreamReader(in, this,
74+
Charset.defaultCharset()); // ## check lock object
7975
}
8076

8177
/**

src/java.base/share/classes/java/io/OutputStreamWriter.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,8 @@ public OutputStreamWriter(OutputStream out, String charsetName)
106106
*/
107107
public OutputStreamWriter(OutputStream out) {
108108
super(out);
109-
try {
110-
se = StreamEncoder.forOutputStreamWriter(out, this, (String)null);
111-
} catch (UnsupportedEncodingException e) {
112-
throw new Error(e);
113-
}
109+
se = StreamEncoder.forOutputStreamWriter(out, this,
110+
Charset.defaultCharset());
114111
}
115112

116113
/**

src/java.base/share/classes/java/lang/CharacterName.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -151,7 +151,7 @@ public String getName(int cp) {
151151
}
152152

153153
public int getCodePoint(String name) {
154-
byte[] bname = name.getBytes(java.nio.charset.StandardCharsets.ISO_8859_1);
154+
byte[] bname = name.getBytes(sun.nio.cs.ISO_8859_1.INSTANCE);
155155
int hsh = hashN(bname, 0, bname.length);
156156
int idx = hsIndices[(hsh & 0x7fffffff) % hsIndices.length];
157157
while (idx != -1) {

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.util.Scanner;
3232
import java.security.AccessController;
3333
import java.io.File;
34-
import java.io.FileNotFoundException;
3534
import java.io.ObjectStreamException;
3635
import java.io.ObjectStreamField;
3736
import java.io.IOException;
@@ -52,6 +51,7 @@
5251
import sun.security.action.*;
5352
import sun.net.InetAddressCachePolicy;
5453
import sun.net.util.IPAddressUtil;
54+
import sun.nio.cs.UTF_8;
5555

5656
/**
5757
* This class represents an Internet Protocol (IP) address.
@@ -984,7 +984,9 @@ public String getHostByAddr(byte[] addr) throws UnknownHostException {
984984
String hostEntry;
985985
String host = null;
986986

987-
try (Scanner hostsFileScanner = new Scanner(new File(hostsFile), "UTF-8")) {
987+
try (Scanner hostsFileScanner = new Scanner(new File(hostsFile),
988+
UTF_8.INSTANCE))
989+
{
988990
while (hostsFileScanner.hasNextLine()) {
989991
hostEntry = hostsFileScanner.nextLine();
990992
if (!hostEntry.startsWith("#")) {
@@ -997,7 +999,7 @@ public String getHostByAddr(byte[] addr) throws UnknownHostException {
997999
}
9981000
}
9991001
}
1000-
} catch (FileNotFoundException e) {
1002+
} catch (IOException e) {
10011003
throw new UnknownHostException("Unable to resolve address "
10021004
+ Arrays.toString(addr) + " as hosts file " + hostsFile
10031005
+ " not found ");
@@ -1033,7 +1035,9 @@ public InetAddress[] lookupAllHostAddr(String host)
10331035
ArrayList<InetAddress> inetAddresses = null;
10341036

10351037
// lookup the file and create a list InetAddress for the specified host
1036-
try (Scanner hostsFileScanner = new Scanner(new File(hostsFile), "UTF-8")) {
1038+
try (Scanner hostsFileScanner = new Scanner(new File(hostsFile),
1039+
UTF_8.INSTANCE))
1040+
{
10371041
while (hostsFileScanner.hasNextLine()) {
10381042
hostEntry = hostsFileScanner.nextLine();
10391043
if (!hostEntry.startsWith("#")) {
@@ -1052,7 +1056,7 @@ public InetAddress[] lookupAllHostAddr(String host)
10521056
}
10531057
}
10541058
}
1055-
} catch (FileNotFoundException e) {
1059+
} catch (IOException e) {
10561060
throw new UnknownHostException("Unable to resolve host " + host
10571061
+ " as hosts file " + hostsFile + " not found ");
10581062
}

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.InputStream;
2929
import java.io.OutputStream;
3030
import java.io.BufferedOutputStream;
31+
import java.nio.charset.StandardCharsets;
3132
import java.security.AccessController;
3233
import java.util.Iterator;
3334

@@ -166,18 +167,10 @@ public PasswordAuthentication run() {
166167
return false;
167168
out.write(1);
168169
out.write(userName.length());
169-
try {
170-
out.write(userName.getBytes("ISO-8859-1"));
171-
} catch (java.io.UnsupportedEncodingException uee) {
172-
assert false;
173-
}
170+
out.write(userName.getBytes(StandardCharsets.ISO_8859_1));
174171
if (password != null) {
175172
out.write(password.length());
176-
try {
177-
out.write(password.getBytes("ISO-8859-1"));
178-
} catch (java.io.UnsupportedEncodingException uee) {
179-
assert false;
180-
}
173+
out.write(password.getBytes(StandardCharsets.ISO_8859_1));
181174
} else
182175
out.write(0);
183176
out.flush();
@@ -208,11 +201,7 @@ private void connectV4(InputStream in, OutputStream out,
208201
out.write((endpoint.getPort() >> 0) & 0xff);
209202
out.write(endpoint.getAddress().getAddress());
210203
String userName = getUserName();
211-
try {
212-
out.write(userName.getBytes("ISO-8859-1"));
213-
} catch (java.io.UnsupportedEncodingException uee) {
214-
assert false;
215-
}
204+
out.write(userName.getBytes(StandardCharsets.ISO_8859_1));
216205
out.write(0);
217206
out.flush();
218207
byte[] data = new byte[8];
@@ -427,11 +416,7 @@ public ProxySelector run() {
427416
if (epoint.isUnresolved()) {
428417
out.write(DOMAIN_NAME);
429418
out.write(epoint.getHostName().length());
430-
try {
431-
out.write(epoint.getHostName().getBytes("ISO-8859-1"));
432-
} catch (java.io.UnsupportedEncodingException uee) {
433-
assert false;
434-
}
419+
out.write(epoint.getHostName().getBytes(StandardCharsets.ISO_8859_1));
435420
out.write((epoint.getPort() >> 8) & 0xff);
436421
out.write((epoint.getPort() >> 0) & 0xff);
437422
} else if (epoint.getAddress() instanceof Inet6Address) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
import jdk.internal.access.JavaNetUriAccess;
4343
import jdk.internal.access.SharedSecrets;
4444
import sun.nio.cs.ThreadLocalCoders;
45+
import sun.nio.cs.UTF_8;
4546

4647
import java.lang.Character; // for javadoc
4748
import java.lang.NullPointerException; // for javadoc
4849

49-
5050
/**
5151
* Represents a Uniform Resource Identifier (URI) reference.
5252
*
@@ -2739,7 +2739,7 @@ private static void appendEscape(StringBuilder sb, byte b) {
27392739
private static void appendEncoded(StringBuilder sb, char c) {
27402740
ByteBuffer bb = null;
27412741
try {
2742-
bb = ThreadLocalCoders.encoderFor("UTF-8")
2742+
bb = ThreadLocalCoders.encoderFor(UTF_8.INSTANCE)
27432743
.encode(CharBuffer.wrap("" + c));
27442744
} catch (CharacterCodingException x) {
27452745
assert false;
@@ -2807,7 +2807,7 @@ private static String encode(String s) {
28072807
String ns = Normalizer.normalize(s, Normalizer.Form.NFC);
28082808
ByteBuffer bb = null;
28092809
try {
2810-
bb = ThreadLocalCoders.encoderFor("UTF-8")
2810+
bb = ThreadLocalCoders.encoderFor(UTF_8.INSTANCE)
28112811
.encode(CharBuffer.wrap(ns));
28122812
} catch (CharacterCodingException x) {
28132813
assert false;
@@ -2865,7 +2865,7 @@ private static String decode(String s, boolean ignorePercentInBrackets) {
28652865
StringBuilder sb = new StringBuilder(n);
28662866
ByteBuffer bb = ByteBuffer.allocate(n);
28672867
CharBuffer cb = CharBuffer.allocate(n);
2868-
CharsetDecoder dec = ThreadLocalCoders.decoderFor("UTF-8")
2868+
CharsetDecoder dec = ThreadLocalCoders.decoderFor(UTF_8.INSTANCE)
28692869
.onMalformedInput(CodingErrorAction.REPLACE)
28702870
.onUnmappableCharacter(CodingErrorAction.REPLACE);
28712871

src/java.base/share/classes/java/nio/file/FileChannelLinesSpliterator.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,10 @@
2424
*/
2525
package java.nio.file;
2626

27+
import sun.nio.cs.ISO_8859_1;
28+
import sun.nio.cs.UTF_8;
29+
import sun.nio.cs.US_ASCII;
30+
2731
import java.io.BufferedReader;
2832
import java.io.IOException;
2933
import java.io.UncheckedIOException;
@@ -32,7 +36,6 @@
3236
import java.nio.channels.FileChannel;
3337
import java.nio.channels.ReadableByteChannel;
3438
import java.nio.charset.Charset;
35-
import java.nio.charset.StandardCharsets;
3639
import java.util.HashSet;
3740
import java.util.Set;
3841
import java.util.Spliterator;
@@ -66,9 +69,9 @@ final class FileChannelLinesSpliterator implements Spliterator<String> {
6669
static final Set<String> SUPPORTED_CHARSET_NAMES;
6770
static {
6871
SUPPORTED_CHARSET_NAMES = new HashSet<>();
69-
SUPPORTED_CHARSET_NAMES.add(StandardCharsets.UTF_8.name());
70-
SUPPORTED_CHARSET_NAMES.add(StandardCharsets.ISO_8859_1.name());
71-
SUPPORTED_CHARSET_NAMES.add(StandardCharsets.US_ASCII.name());
72+
SUPPORTED_CHARSET_NAMES.add(UTF_8.INSTANCE.name());
73+
SUPPORTED_CHARSET_NAMES.add(ISO_8859_1.INSTANCE.name());
74+
SUPPORTED_CHARSET_NAMES.add(US_ASCII.INSTANCE.name());
7275
}
7376

7477
private final FileChannel fc;

0 commit comments

Comments
 (0)