8167252: Some of Charset.availableCharsets() does not contain itself
Reviewed-by: bpb, alanb, iris, lancea, jpai
This commit is contained in:
parent
653a8d0cce
commit
3eeb681a0d
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2023, 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
|
||||
@ -45,6 +45,12 @@ abstract class Unicode extends Charset
|
||||
|| (cs instanceof UTF_16BE)
|
||||
|| (cs instanceof UTF_16LE)
|
||||
|| (cs instanceof UTF_16LE_BOM)
|
||||
|| (cs instanceof CESU_8)
|
||||
|| (cs instanceof UTF_32)
|
||||
|| (cs instanceof UTF_32BE)
|
||||
|| (cs instanceof UTF_32BE_BOM)
|
||||
|| (cs instanceof UTF_32LE)
|
||||
|| (cs instanceof UTF_32LE_BOM)
|
||||
|| (cs.name().equals("GBK"))
|
||||
|| (cs.name().equals("GB18030"))
|
||||
|| (cs.name().equals("ISO-8859-2"))
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2023, 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
|
||||
@ -51,7 +51,8 @@ public class EUC_JP_Open
|
||||
public boolean contains(Charset cs) {
|
||||
return ((cs.name().equals("US-ASCII"))
|
||||
|| (cs instanceof JIS_X_0201)
|
||||
|| (cs instanceof EUC_JP));
|
||||
|| (cs instanceof EUC_JP)
|
||||
|| (cs instanceof EUC_JP_Open));
|
||||
}
|
||||
|
||||
public CharsetDecoder newDecoder() {
|
||||
|
@ -59,7 +59,8 @@ public class JISAutoDetect
|
||||
return ((cs.name().equals("US-ASCII"))
|
||||
|| (cs instanceof SJIS)
|
||||
|| (cs instanceof EUC_JP)
|
||||
|| (cs instanceof ISO2022_JP));
|
||||
|| (cs instanceof ISO2022_JP)
|
||||
|| (cs instanceof JISAutoDetect));
|
||||
}
|
||||
|
||||
public boolean canEncode() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2010, 2023, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/* @test
|
||||
* @summary Unit test for charset containment
|
||||
* @bug 6798572
|
||||
* @bug 6798572 8167252
|
||||
* @modules jdk.charsets
|
||||
*/
|
||||
|
||||
@ -93,6 +93,8 @@ public class Contains {
|
||||
ck(cp1252, cp1252, true);
|
||||
|
||||
checkUTF();
|
||||
|
||||
containsSelfTest();
|
||||
}
|
||||
|
||||
static void checkUTF() throws Exception {
|
||||
@ -103,6 +105,27 @@ public class Contains {
|
||||
true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the assertion in the contains() method: "Every charset contains itself."
|
||||
*/
|
||||
static void containsSelfTest() {
|
||||
boolean failed = false;
|
||||
|
||||
for (var entry : Charset.availableCharsets().entrySet()) {
|
||||
Charset charset = entry.getValue();
|
||||
boolean contains = charset.contains(charset);
|
||||
|
||||
System.out.println("Charset(" + charset.name() + ").contains(Charset(" + charset.name()
|
||||
+ ")) returns " + contains);
|
||||
if (!contains) {
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
if (failed) {
|
||||
throw new RuntimeException("Charset.contains(itself) returns false for some charsets");
|
||||
}
|
||||
}
|
||||
|
||||
static String[] utfNames = {"utf-16",
|
||||
"utf-8",
|
||||
"utf-16le",
|
||||
|
Loading…
Reference in New Issue
Block a user