test/jdk/java/lang/Integer/ParsingTest.java
author herrick
Mon, 14 Oct 2019 14:36:45 -0400
branchJDK-8200758-branch
changeset 58584 910b14f4fe3a
parent 47216 71c04702a3d5
permissions -rw-r--r--
8232042: [macos] Installation fails if application name contains spaces Submitted-by: almatvee Reviewed-by: aherrick, asemenyuk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1826
diff changeset
     2
 * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved.
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
     4
 *
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
     7
 * published by the Free Software Foundation.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
     8
 *
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    13
 * accompanied this code).
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    14
 *
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1826
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1826
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1826
diff changeset
    21
 * questions.
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    22
 */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    23
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    24
/*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    25
 * @test
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    26
 * @bug 5017980 6576055 8041972 8055251
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    27
 * @summary Test parsing methods
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    28
 * @author Joseph D. Darcy
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    29
 */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    30
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
    31
import java.lang.IndexOutOfBoundsException;
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
    32
import java.lang.NullPointerException;
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
    33
import java.lang.RuntimeException;
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    34
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    35
/**
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    36
 * There are seven methods in java.lang.Integer which transform strings
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    37
 * into an int or Integer value:
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    38
 *
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    39
 * public Integer(String s)
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    40
 * public static Integer decode(String nm)
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    41
 * public static int parseInt(CharSequence s, int beginIndex, int endIndex, int radix)
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    42
 * public static int parseInt(String s, int radix)
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    43
 * public static int parseInt(String s)
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    44
 * public static Integer valueOf(String s, int radix)
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    45
 * public static Integer valueOf(String s)
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    46
 *
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    47
 * Besides decode, all the methods and constructor call down into
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
    48
 * parseInt(CharSequence, int, int, int) to do the actual work.  Therefore, the
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
    49
 * behavior of parseInt(CharSequence, int, int, int) will be tested here.
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
    50
 *
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    51
 */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    52
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    53
public class ParsingTest {
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
    54
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    55
    public static void main(String... argv) {
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    56
        check(+100, "+100");
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    57
        check(-100, "-100");
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    58
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    59
        check(0, "+0");
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    60
        check(0, "-0");
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    61
        check(0, "+00000");
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    62
        check(0, "-00000");
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    63
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    64
        check(0, "0");
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    65
        check(1, "1");
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    66
        check(9, "9");
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    67
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
    68
        checkFailure("");
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    69
        checkFailure("\u0000");
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    70
        checkFailure("\u002f");
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    71
        checkFailure("+");
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    72
        checkFailure("-");
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    73
        checkFailure("++");
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    74
        checkFailure("+-");
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    75
        checkFailure("-+");
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    76
        checkFailure("--");
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    77
        checkFailure("++100");
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    78
        checkFailure("--100");
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    79
        checkFailure("+-6");
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    80
        checkFailure("-+6");
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    81
        checkFailure("*100");
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
    82
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    83
        // check offset based methods
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    84
        check(0, "+00000", 0, 6, 10);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    85
        check(0, "-00000", 0, 6, 10);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    86
        check(0, "test-00000", 4, 10, 10);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    87
        check(-12345, "test-12345", 4, 10, 10);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    88
        check(12345, "xx12345yy", 2, 7, 10);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    89
        check(15, "xxFyy", 2, 3, 16);
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
    90
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    91
        checkNumberFormatException("", 0, 0, 10);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    92
        checkNumberFormatException("+-6", 0, 3, 10);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    93
        checkNumberFormatException("1000000", 7, 7, 10);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    94
        checkNumberFormatException("1000000", 0, 2, Character.MAX_RADIX + 1);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    95
        checkNumberFormatException("1000000", 0, 2, Character.MIN_RADIX - 1);
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
    96
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    97
        checkIndexOutOfBoundsException("1000000", 10, 4, 10);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    98
        checkIndexOutOfBoundsException("1000000", -1, 2, Character.MAX_RADIX + 1);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
    99
        checkIndexOutOfBoundsException("1000000", -1, 2, Character.MIN_RADIX - 1);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   100
        checkIndexOutOfBoundsException("1000000", 10, 2, Character.MAX_RADIX + 1);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   101
        checkIndexOutOfBoundsException("1000000", 10, 2, Character.MIN_RADIX - 1);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   102
        checkIndexOutOfBoundsException("-1", 0, 3, 10);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   103
        checkIndexOutOfBoundsException("-1", 2, 3, 10);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   104
        checkIndexOutOfBoundsException("-1", -1, 2, 10);
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   105
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   106
        checkNull(0, 1, 10);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   107
        checkNull(-1, 0, 10);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   108
        checkNull(0, 0, 10);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   109
        checkNull(0, -1, 10);
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   110
        checkNull(-1, -1, -1);
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   111
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   112
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   113
    private static void check(int expected, String val) {
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   114
        int n = Integer.parseInt(val);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   115
        if (n != expected)
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   116
            throw new RuntimeException("Integer.parseInt failed. String:" +
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   117
                                                val + " Result:" + n);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   118
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   119
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   120
    private static void checkFailure(String val) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   121
        int n = 0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   122
        try {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   123
            n = Integer.parseInt(val);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   124
            System.err.println("parseInt(" + val + ") incorrectly returned " + n);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   125
            throw new RuntimeException();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   126
        } catch (NumberFormatException nfe) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   127
            ; // Expected
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   128
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   129
    }
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   130
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   131
    private static void checkNumberFormatException(String val, int start, int end, int radix) {
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   132
        int n = 0;
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   133
        try {
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   134
            n = Integer.parseInt(val, start, end, radix);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   135
            System.err.println("parseInt(" + val + ", " + start + ", " + end + ", " + radix +
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   136
                    ") incorrectly returned " + n);
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   137
            throw new RuntimeException();
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   138
        } catch (NumberFormatException nfe) {
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   139
            ; // Expected
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   140
        }
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   141
    }
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   142
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   143
    private static void checkIndexOutOfBoundsException(String val, int start, int end, int radix) {
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   144
        int n = 0;
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   145
        try {
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   146
            n = Integer.parseInt(val, start, end, radix);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   147
            System.err.println("parseInt(" + val + ", " + start + ", " + end + ", " + radix  +
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   148
                    ") incorrectly returned " + n);
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   149
            throw new RuntimeException();
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   150
        } catch (IndexOutOfBoundsException ioob) {
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   151
            ; // Expected
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   152
        }
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   153
    }
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   154
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   155
    private static void checkNull(int start, int end, int radix) {
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   156
        int n = 0;
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   157
        try {
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   158
            n = Integer.parseInt(null, start, end, radix);
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   159
            System.err.println("parseInt(null, " + start + ", " + end + ", " + radix +
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   160
                    ") incorrectly returned " + n);
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   161
            throw new RuntimeException();
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   162
        } catch (NullPointerException npe) {
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   163
            ; // Expected
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   164
        }
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   165
    }
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   166
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   167
    private static void check(int expected, String val, int start, int end, int radix) {
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   168
        int n = Integer.parseInt(val, start, end, radix);
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   169
        if (n != expected)
26462
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   170
            throw new RuntimeException("Integer.parsedInt failed. Expected: " + expected + " String: \"" +
d6d34934be12 8055251: Re-examine Integer.parseInt and Long.parseLong methods
alanb
parents: 25653
diff changeset
   171
                    val + "\", start: " + start + ", end: " + end + ", radix: " + radix + " Result:" + n);
25653
41e5fa7ce490 8041972: Additional parse methods for Long/Integer
redestad
parents: 5506
diff changeset
   172
    }
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   173
}