jdk/test/java/text/Format/DateFormat/Bug8081794.java
author okutsu
Thu, 01 Oct 2015 15:16:35 +0900
changeset 32847 9409488183a6
permissions -rw-r--r--
8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem Reviewed-by: peytoia, okutsu Contributed-by: Naveen Kumar <naveen.ah.kumar@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32847
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
     1
/*
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
     4
 *
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
     8
 *
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    13
 * accompanied this code).
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    14
 *
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    18
 *
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    21
 * questions.
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    22
 */
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    23
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    24
/*
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    25
 * @test
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    26
 * @bug 8081794
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    27
 * @summary ParsePosition getErrorIndex should return correct index
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    28
 */
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    29
import java.text.ParsePosition;
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    30
import java.text.SimpleDateFormat;
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    31
import java.util.Date;
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    32
import java.util.Locale;
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    33
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    34
public class Bug8081794 {
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    35
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    36
    public static void main(String[] args) {
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    37
        String date = "13 Jan 2005 21:45:34 ABC";
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    38
        String format = "dd MMM yyyy HH:mm:ss z";
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    39
        ParsePosition pp = new ParsePosition(0);
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    40
        pp.setIndex(0);
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    41
        SimpleDateFormat sd = new SimpleDateFormat(format, Locale.ENGLISH);
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    42
        Date d = sd.parse(date, pp);
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    43
        int errorIndex = pp.getErrorIndex();
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    44
        if (errorIndex == 21) {
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    45
            System.out.println(": passed");
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    46
        } else {
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    47
            System.out.println(": failed");
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    48
            throw new RuntimeException("Failed with wrong index: " + errorIndex);
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    49
        }
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    50
    }
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents:
diff changeset
    51
}