Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/nio/charset/Charset/EmptyCharsetName.java
38821 views
/*1* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 478688425* @summary Ensure that passing the empty string to Charset methods and26* constructors causes an IllegalArgumentException to be thrown27*28* @build EmptyCharsetName29* @run main EmptyCharsetName30* @run main/othervm -Dsun.nio.cs.bugLevel=1.4 EmptyCharsetName31*/3233import java.io.*;34import java.nio.*;35import java.nio.charset.*;363738public class EmptyCharsetName {3940static boolean compat;4142static abstract class Test {4344public abstract void go() throws Exception;4546Test() throws Exception {47try {48go();49} catch (Exception x) {50if (compat) {51if (x instanceof UnsupportedCharsetException) {52System.err.println("Thrown as expected: " + x);53return;54}55throw new Exception("Exception thrown", x);56}57if (x instanceof IllegalCharsetNameException) {58System.err.println("Thrown as expected: " + x);59return;60}61throw new Exception("Incorrect exception: "62+ x.getClass().getName(),63x);64}65if (!compat)66throw new Exception("No exception thrown");67}6869}7071public static void main(String[] args) throws Exception {7273// If sun.nio.cs.bugLevel == 1.4 then we want the 1.4 behavior74String bl = System.getProperty("sun.nio.cs.bugLevel");75compat = (bl != null && bl.equals("1.4"));7677new Test() {78public void go() throws Exception {79Charset.forName("");80}};81new Test() {82public void go() throws Exception {83Charset.isSupported("");84}};85new Test() {86public void go() throws Exception {87new Charset("", new String[] { }) {88public CharsetDecoder newDecoder() {89return null;90}91public CharsetEncoder newEncoder() {92return null;93}94public boolean contains(Charset cs) {95return false;96}97};98}};99}100101}102103104