File tree Expand file tree Collapse file tree 4 files changed +37
-6
lines changed
java.base/share/classes/sun/nio/cs
jdk.charsets/share/classes/sun/nio/cs/ext
test/jdk/java/nio/charset/Charset Expand file tree Collapse file tree 4 files changed +37
-6
lines changed Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2005, 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
@@ -45,6 +45,12 @@ public boolean contains(Charset cs) {
4545 || (cs instanceof UTF_16BE )
4646 || (cs instanceof UTF_16LE )
4747 || (cs instanceof UTF_16LE_BOM )
48+ || (cs instanceof CESU_8 )
49+ || (cs instanceof UTF_32 )
50+ || (cs instanceof UTF_32BE )
51+ || (cs instanceof UTF_32BE_BOM )
52+ || (cs instanceof UTF_32LE )
53+ || (cs instanceof UTF_32LE_BOM )
4854 || (cs .name ().equals ("GBK" ))
4955 || (cs .name ().equals ("GB18030" ))
5056 || (cs .name ().equals ("ISO-8859-2" ))
Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2003, 2015 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2003, 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
@@ -51,7 +51,8 @@ public class EUC_JP_Open
5151 public boolean contains(Charset cs) {
5252 return ((cs.name().equals("US-ASCII"))
5353 || (cs instanceof JIS_X_0201)
54- || (cs instanceof EUC_JP));
54+ || (cs instanceof EUC_JP)
55+ || (cs instanceof EUC_JP_Open));
5556 }
5657
5758 public CharsetDecoder newDecoder() {
Original file line number Diff line number Diff line change @@ -59,7 +59,8 @@ public boolean contains(Charset cs) {
5959 return ((cs .name ().equals ("US-ASCII" ))
6060 || (cs instanceof SJIS )
6161 || (cs instanceof EUC_JP )
62- || (cs instanceof ISO2022_JP ));
62+ || (cs instanceof ISO2022_JP )
63+ || (cs instanceof JISAutoDetect ));
6364 }
6465
6566 public boolean canEncode () {
Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2010, 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
2323
2424/* @test
2525 * @summary Unit test for charset containment
26- * @bug 6798572
26+ * @bug 6798572 8167252
2727 * @modules jdk.charsets
2828 */
2929
@@ -93,6 +93,8 @@ public static void main(String[] args) throws Exception {
9393 ck (cp1252 , cp1252 , true );
9494
9595 checkUTF ();
96+
97+ containsSelfTest ();
9698 }
9799
98100 static void checkUTF () throws Exception {
@@ -103,6 +105,27 @@ static void checkUTF() throws Exception {
103105 true );
104106 }
105107
108+ /**
109+ * Tests the assertion in the contains() method: "Every charset contains itself."
110+ */
111+ static void containsSelfTest () {
112+ boolean failed = false ;
113+
114+ for (var entry : Charset .availableCharsets ().entrySet ()) {
115+ Charset charset = entry .getValue ();
116+ boolean contains = charset .contains (charset );
117+
118+ System .out .println ("Charset(" + charset .name () + ").contains(Charset(" + charset .name ()
119+ + ")) returns " + contains );
120+ if (!contains ) {
121+ failed = true ;
122+ }
123+ }
124+ if (failed ) {
125+ throw new RuntimeException ("Charset.contains(itself) returns false for some charsets" );
126+ }
127+ }
128+
106129 static String [] utfNames = {"utf-16" ,
107130 "utf-8" ,
108131 "utf-16le" ,
You can’t perform that action at this time.
0 commit comments