Path: blob/master/test/jdk/sun/nio/cs/ConvertSingle.java
41149 views
/*1* Copyright (c) 2008, 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 409498725@summary Verify that malformed expression exceptions are thrown26but no internal errors in certain pathologial cases.2728*/293031import java.io.*;32import java.nio.charset.*;3334public class ConvertSingle {3536public static void main(String args[]) throws Exception {37// This conversion is pathologically bad - it is attempting to38// read unicode from an ascii encoded string.39// The orignal bug: A internal error in ISR results if the40// byte counter in ByteToCharUnicode41// is not advanced as the input is consumed.4243try{44String s = "\n";45byte ss[] = null;46String sstring = "x";47ss = s.getBytes();48ByteArrayInputStream BAIS = new ByteArrayInputStream(ss);49InputStreamReader ISR = new InputStreamReader(BAIS, "Unicode");50BufferedReader BR = new BufferedReader(ISR);51sstring = BR.readLine();52BR.close();53System.out.println(sstring);54} catch (MalformedInputException e){55// Right error56return;57} catch (java.lang.InternalError e) {58throw new Exception("ByteToCharUnicode is failing incorrectly for "59+ " single byte input");60}6162}6364}656667