Skip to content

Commit 287bb06

Browse files
Sergey TsypanovAlan Bateman
Sergey Tsypanov
authored and
Alan Bateman
committed
8305902: (cs) Resolve default Charset only once in StreamEncoder and StreamDecoder
Reviewed-by: alanb, bpb
1 parent 8a1639d commit 287bb06

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

src/java.base/share/classes/sun/nio/cs/StreamDecoder.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2023, 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
@@ -71,14 +71,10 @@ public static StreamDecoder forInputStreamReader(InputStream in,
7171
String charsetName)
7272
throws UnsupportedEncodingException
7373
{
74-
String csn = charsetName;
75-
if (csn == null) {
76-
csn = Charset.defaultCharset().name();
77-
}
7874
try {
79-
return new StreamDecoder(in, lock, Charset.forName(csn));
75+
return new StreamDecoder(in, lock, Charset.forName(charsetName));
8076
} catch (IllegalCharsetNameException | UnsupportedCharsetException x) {
81-
throw new UnsupportedEncodingException (csn);
77+
throw new UnsupportedEncodingException (charsetName);
8278
}
8379
}
8480

src/java.base/share/classes/sun/nio/cs/StreamEncoder.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2023, 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
@@ -58,14 +58,10 @@ public static StreamEncoder forOutputStreamWriter(OutputStream out,
5858
String charsetName)
5959
throws UnsupportedEncodingException
6060
{
61-
String csn = charsetName;
62-
if (csn == null) {
63-
csn = Charset.defaultCharset().name();
64-
}
6561
try {
66-
return new StreamEncoder(out, lock, Charset.forName(csn));
62+
return new StreamEncoder(out, lock, Charset.forName(charsetName));
6763
} catch (IllegalCharsetNameException | UnsupportedCharsetException x) {
68-
throw new UnsupportedEncodingException (csn);
64+
throw new UnsupportedEncodingException (charsetName);
6965
}
7066
}
7167

0 commit comments

Comments
 (0)