gt:         DecimalFormatSymbols dfsEG = dfEG.getDecimalFormatSymbols();
context: /*
   * Copyright 2008 Sun Microsystems, Inc.  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
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.
   *
   * This code is distributed in the hope that it will be useful, but WITHOUT
   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   * version 2 for more details (a copy is included in the LICENSE file that
   * accompanied this code).
   *
   * You should have received a copy of the GNU General Public License version
   * 2 along with this work; if not, write to the Free Software Foundation,
   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   *
   * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   * CA 95054 USA or visit www.sun.com if you need additional information or
   * have any questions.
   */
  
  /**
   * @test
   * @bug 4823811
   * @summary Confirm that text which includes numbers with a trailing minus sign is parsed correctly.
   * @run main/othervm -Duser.timezone=GMT+09:00 Bug4823811
   */
  
  import java.text.*;
  import java.util.*;
  
  public class Bug4823811 {
  
      private static Locale localeEG = new Locale("ar", "EG");
      private static Locale localeUS = Locale.US;
  
      private static String JuneInArabic = "\u064a\u0648\u0646\u064a\u0648";
      private static String JulyInArabic = "\u064a\u0648\u0644\u064a\u0648";
      private static String JuneInEnglish = "June";
      private static String JulyInEnglish = "July";
  
      private static String BORDER =
          "============================================================";
  
      /*
       * I don't use static import here intentionally so that this test program
       * can be run on JDK 1.4.2.
       */
      private static int ERA = Calendar.ERA;
      private static int BC = GregorianCalendar.BC;
  //    private static int JAN = Calendar.JANUARY;
  //    private static int FEB = Calendar.FEBRUARY;
  //    private static int MAR = Calendar.MARCH;
      private static int APR = Calendar.APRIL;
      private static int MAY = Calendar.MAY;
      private static int JUN = Calendar.JUNE;
      private static int JUL = Calendar.JULY;
  //    private static int AUG = Calendar.AUGUST;
  //    private static int SEP = Calendar.SEPTEMBER;
  //    private static int OCT = Calendar.OCTOBER;
  //    private static int NOV = Calendar.NOVEMBER;
  //    private static int DEC = Calendar.DECEMBER;
  
      private static String[] patterns = {
          "yyyy MMMM d H m s",
          "yyyy MM dd hh mm ss",
  
          /*
           * Because 1-based HOUR_OF_DAY, 1-based HOUR, MONTH, and YEAR fields
           * are parsed using different code from the code for other numeric
           * fields, I prepared YEAR-preceding patterns and SECOND-preceding
           * patterns.
           */
          "yyyy M d h m s",
          " yyyy M d h m s",
          "yyyy M d h m s ",
  
          "s m h d M yyyy",
          " s m h d M yyyy",
          "s m h d M yyyy ",
      };
  
      private static char originalMinusSign1 = ':';
      private static char originalMinusSign2 = '\uff0d';  // fullwidth minus
      private static String[] delimiters = {"-", "/", ":", "/", "\uff0d", "/"};
      private static String[][] specialDelimiters = {
          // for Arabic formatter and modified English formatter
          {"--", "-/", "::", ":/", "\uff0d\uff0d", "\uff0d/"},
  
          // for English formatter and modified Arabic formatter
          {"--", "/-", "::", "/:", "\uff0d\uff0d", "/\uff0d"},
      };
  
      /*
       * Format:
       *   +-------------------------------------------------------------------+
       *   | Input               | Output                                      |
       *   +---------------------+---------------------------------------------|
       *   | datesEG & datesUS   | formattedDatesEG & formattedDatesUS         |
       *   +-------------------------------------------------------------------+
       *
       * Parse:
       *   +-------------------------------------------------------------------+
       *   | Input               | Output                                      |
       *   |---------------------+---------------------------------------------|
       *   | datesToParse        | datesEG & datesUS                           |
       *   +-------------------------------------------------------------------+
       */
      private static String[][] datesToParse = {
          // "JUNE" and "JULY" are replaced with a localized month name later.
          {"2008 JULY 20 3 12 83",
           "2008  JULY 20 3 12 83",
           "2008 JULY  20 3 12 83"},
  
          {"2008 07 20 03 12 83",
           "2008  07 20 03 12 83",
           "2008 07  20 03 12 83"},
  
          {"2008 7 20 3 12 83",
           "2008  7 20  3 12 83",
           "2008 7  20  3 12 83"},
  
          {" 2008 7 20 3 12 83",
           "  2008 7 20 3 12 83",
           " 2008  7 20 3 12 83",
           "2008 7 20 3 12 83"},
  
          {"2008 7 20 3 12 83 ",
           "2008 7 20 3 12 83  ",
           "2008 7 20 3 12 83"},
  
          {"83 12 3 20 7 2008",
           "83  12 3  20 7 2008",
           "83 12  3  20 7 2008"},
  
          {" 83 12 3 20 7 2008",
           "  83 12 3 20 7 2008",
           " 83  12 3 20 7 2008",
           "83 12 3 20 7 2008"},
  
          {"83 12 3 20 7 2008 ",
           "83 12 3 20 7 2008  ",
           "83 12 3 20 7 2008"},
      };
  
      // For formatting
      private static String[][] formattedDatesEG = {
          {"2008 JULY 20 3 13 23",
           "2009 JULY 20 3 13 23",
           null},
  
          {"2008 07 20 03 13 23",
           "2009 07 20 03 13 23",
           "2007 05 20 03 13 23"},
  
          {"2008 7 20 3 13 23",
           "2009 6 10 3 13 23",
           "2007 4 10 3 13 23"},
  
          {" 2008 7 20 3 13 23",
           null,
           " 2009 7 20 3 13 23",
           null},
  
          {"2008 7 20 3 13 23 ",
           "2008 7 20 3 10 37 ",
           null},
  
          {"23 13 3 20 7 2008",
           "37 10 9 19 7 2008",
           "23 49 8 19 7 2008"},
  
          {" 23 13 3 20 7 2008",
           null,
           " 37 10 3 20 7 2008",
           null},
  
          {"23 13 3 20 7 2008 ",
           "23 13 3 20 7 2009 ",
           null},
      };
  
      private static String[][] formattedDatesUS = {
          {"2008 JULY 20 3 13 23",
           null,
           "2008 JUNE 10 3 13 23"},
  
          {"2008 07 20 03 13 23",
           "2007 05 20 03 13 23",
           "2008 06 10 03 13 23"},
  
          {"2008 7 20 3 13 23",
           "2007 5 19 9 13 23",
           "2008 6 9 9 13 23"},
  
          {" 2008 7 20 3 13 23",
           " 2009 7 20 3 13 23",
           " 2007 5 20 3 13 23",
           null},
  
          {"2008 7 20 3 13 23 ",
           "2008 7 20 3 13 23 ",
           null},
  
          {"23 13 3 20 7 2008",
           "23 49 2 10 6 2008",
           "23 13 9 9 6 2008"},
  
          {" 23 13 3 20 7 2008",
           " 37 10 3 20 7 2008",
           " 23 49 2 20 7 2008",
           null},
  
          {"23 13 3 20 7 2008 ",
           "23 13 3 20 7 2008 ",
           null},
      };
  
      private static GregorianCalendar[][] datesEG = {
          {new GregorianCalendar( 2008, JUL,  20,  3,  12,  83),
           new GregorianCalendar(-2008, JUL,  20,  3,  12,  83),
           null},
  
          {new GregorianCalendar( 2008, JUL,  20,  3,  12,  83),
           new GregorianCalendar(-2008, JUL,  20,  3,  12,  83),
           new GregorianCalendar( 2007, MAY,  20,  3,  12,  83)},
  
          {new GregorianCalendar( 2008, JUL,  20,  3,  12,  83),
           new GregorianCalendar(-2008, JUL, -20,  3,  12,  83),
           new GregorianCalendar( 2007, APR,  10,  3,  12,  83)},
  
          {new GregorianCalendar( 2008, JUL,  20,  3,  12,  83),
           null,
           new GregorianCalendar(-2008, JUL,  20,  3,  12,  83),
           null},
  
          {new GregorianCalendar( 2008, JUL,  20,  3,  12,  83),
           new GregorianCalendar( 2008, JUL,  20,  3,  12, -83),
           null},
  
          {new GregorianCalendar( 2008, JUL,  20,  3,  12,  83),
           new GregorianCalendar( 2008, JUL,  20, -3,  12, -83),
           new GregorianCalendar( 2008, JUL,  20, -3, -12,  83)},
  
          {new GregorianCalendar( 2008, JUL,  20,  3,  12,  83),
           null,
           new GregorianCalendar( 2008, JUL,  20,  3,  12, -83),
           null},
  
          {new GregorianCalendar( 2008, JUL,  20,  3,  12,  83),
           new GregorianCalendar(-2008, JUL,  20,  3,  12,  83),
           null},
      };
  
      private static GregorianCalendar[][] datesUS = {
          {new GregorianCalendar( 2008, JUL,  20,  3,  12,  83),
           null,
           new GregorianCalendar( 2008, JUN,  10,  3,  12,  83)},
  
          {new GregorianCalendar( 2008, JUL,  20,  3,  12,  83),
           new GregorianCalendar( 2007, MAY,  20,  3,  12,  83),
           new GregorianCalendar( 2008, JUN,  10,  3,  12,  83)},
  
          {new GregorianCalendar( 2008, JUL,  20,  3,  12,  83),
           new GregorianCalendar( 2007, MAY,  20, -3,  12,  83),
           new GregorianCalendar( 2008, JUL, -20, -3,  12,  83)},
  
          {new GregorianCalendar( 2008, JUL,  20,  3,  12,  83),
           new GregorianCalendar(-2008, JUL,  20,  3,  12,  83),
           new GregorianCalendar( 2007, MAY,  20,  3,  12,  83),
           null},
  
          {new GregorianCalendar( 2008, JUL,  20,  3,  12,  83),
           new GregorianCalendar( 2008, JUL,  20,  3,  12,  83),
           null},
  
          {new GregorianCalendar( 2008, JUL,  20,  3,  12,  83),
           new GregorianCalendar( 2008, JUL, -20,  3, -12,  83),
           new GregorianCalendar( 2008, JUL, -20, -3,  12,  83)},
  
          {new GregorianCalendar( 2008, JUL,  20,  3,  12,  83),
           new GregorianCalendar( 2008, JUL,  20,  3,  12, -83),
           new GregorianCalendar( 2008, JUL,  20,  3, -12,  83),
           null},
  
          {new GregorianCalendar( 2008, JUL,  20,  3,  12,  83),
           new GregorianCalendar( 2008, JUL,  20,  3,  12,  83),
           null},
      };
  
      /* flags */
      private static boolean err = false;
      private static boolean verbose = false;
  
  
      public static void main(String[] args) {
          if (args.length == 1 && args[0].equals("-v")) {
              verbose = true;
          }
  
          Locale defaultLocale = Locale.getDefault();
          TimeZone defaultTimeZone = TimeZone.getDefault();
  
          TimeZone.setDefault(TimeZone.getTimeZone("Asia/Tokyo"));
  
          try {
              /*
               * Test SimpleDateFormat.parse() and format() for original
               * SimpleDateFormat instances
               */
              testDateFormat1();
  
              /*
               * Test SimpleDateFormat.parse() and format() for modified
               * SimpleDateFormat instances using an original minus sign,
               * pattern, and diffenrent month names in DecimalFormat
               */
              testDateFormat2();
  
              /*
               * Test SimpleDateFormat.parse() and format() for modified
               * SimpleDateFormat instances using a fullwidth minus sign
               */
              testDateFormat3();
  
              /*
               * Just to confirm that regressions aren't introduced in
               * DecimalFormat. This cannot happen, though. Because I didn't
               * change DecimalFormat at all.
               */
              testNumberFormat();
          }
          catch (Exception e) {
              err = true;
              System.err.println("Unexpected exception: " + e);
          }
          finally {
              Locale.setDefault(defaultLocale);
              TimeZone.setDefault(defaultTimeZone);
  
              if (err) {
                  System.err.println(BORDER + " Test failed.");
                  throw new RuntimeException("Date/Number formatting/parsing error.");
              } else {
                  System.out.println(BORDER + " Test passed.");
              }
          }
      }
  
  
      //
      // DateFormat test
      //
      private static void testDateFormat1() {
          for (int i = 0; i < patterns.length; i++) {
              System.out.println(BORDER);
              for (int j = 0; j <= 1; j++) {
                  // Generate a pattern
                  String pattern = patterns[i].replaceAll(" ", delimiters[j]);
                  System.out.println("Pattern=\"" + pattern + "\"");
  
                  System.out.println("*** DateFormat.format test in ar_EG");
                  testDateFormatFormattingInRTL(pattern, i, j, null, localeEG, false);
  
                  System.out.println("*** DateFormat.parse test in ar_EG");
                  testDateFormatParsingInRTL(pattern, i, j, null, localeEG, false);
  
                  System.out.println("*** DateFormat.format test in en_US");
                  testDateFormatFormattingInLTR(pattern, i, j, null, localeUS, true);
  
                  System.out.println("*** DateFormat.parse test in en_US");
                  testDateFormatParsingInLTR(pattern, i, j, null, localeUS, true);
              }
          }
      }
  
      private static void testDateFormat2() {
          /*
           * modified ar_EG Date&Time formatter :
           *   minus sign:  ':'
           *   pattern:     "#,##0.###"
           *   month names: In Arabic
           *
           * modified en_US Date&Time formatter :
           *   minus sign:  ':'
           *   pattern:     "#,##0.###;#,##0.###-"
           *   month names: In English
           */
          DecimalFormat dfEG = (DecimalFormat)NumberFormat.getInstance(localeEG);
          DecimalFormat dfUS = (DecimalFormat)NumberFormat.getInstance(localeUS);
  
  