Path: blob/master/test/jdk/java/text/Format/MessageFormat/bug4492719.java
41152 views
/*1* Copyright (c) 2001, 2016, 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/*24* @test25*26* @bug 449271927* @library /java/text/testlib28* @summary Confirm that Message.parse() interprets time zone which uses "GMT+/-" format correctly and doesn't throw ParseException.29*/3031import java.util.*;32import java.text.*;3334public class bug4492719 extends IntlTest {3536public static void main(String[] args) throws Exception {37Locale savedLocale = Locale.getDefault();38TimeZone savedTimeZone = TimeZone.getDefault();39MessageFormat mf;40boolean err =false;4142String[] formats = {43"short", "medium", "long", "full"44};45String[] timezones = {46"America/Los_Angeles", "GMT", "GMT+09:00", "GMT-8:00",47"GMT+123", "GMT-1234", "GMT+2", "GMT-13"48};49String text;5051Locale.setDefault(Locale.US);5253try {54for (int i = 0; i < timezones.length; i++) {55TimeZone.setDefault(TimeZone.getTimeZone(timezones[i]));5657for (int j = 0; j < formats.length; j++) {58mf = new MessageFormat("{0,time," + formats[j] + "} - time");59text = MessageFormat.format("{0,time," + formats[j] + "} - time",60new Object [] { new Date(123456789012L)});61Object[] objs = mf.parse(text);62}63}64} catch (ParseException e) {65err = true;66System.err.println("Invalid ParseException occurred : " +67e.getMessage());68System.err.println(" TimeZone=" + TimeZone.getDefault());69}70finally {71Locale.setDefault(savedLocale);72TimeZone.setDefault(savedTimeZone);73if (err) {74throw new Exception("MessageFormat.parse(\"GMT format\") failed.");75}76}77}78}798081