test/jdk/java/lang/String/Exceptions.java
author jlaskey
Fri, 18 May 2018 08:43:49 -0300
changeset 50175 589ed2770141
parent 47216 71c04702a3d5
permissions -rw-r--r--
8200436: String::isBlank Reviewed-by: sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4472841 4703640 4705681 4705683 4833095 5005831
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Verify that constructor exceptions are thrown as expected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.UnsupportedEncodingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.nio.charset.Charset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
public class Exceptions {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    private static final byte [] b = { 0x48, 0x69, 0x2c, 0x20,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
                                       0x44, 0x75, 0x6b, 0x65, 0x21 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    private static final char [] c
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
        = "Attack of the Killer Tomatoes!".toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private static boolean ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static void fail(Class ex, String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        System.err.println("expected " + ex.getName() + " for " + s
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
                               + " - FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static void pass(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        System.out.println(s + " -- OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static void tryCatch(String s, Class ex, Runnable thunk) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        Throwable t = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            thunk.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        } catch (Throwable x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            if (ex.isAssignableFrom(x.getClass()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                t = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                x.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        if ((t == null) && (ex != null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            fail(ex, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            pass(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // -- Constructors --
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static void noArgs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        System.out.println("String()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        tryCatch("  default ctor", null, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                    new String();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static void string() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        System.out.println("String(String original)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        tryCatch("  \"foo\"", null, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                    new String("foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    new String((String) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private static void charArray() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        System.out.println("String(char value[])");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        tryCatch("  char [] = \"Duke says \"Hi!\"\"", null, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                    new String("Duke says \"Hi!\"".toCharArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    new String((char []) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private static void charArrayOffCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        System.out.println("String(char value[], int offset, int count)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        tryCatch("  c, 0, 3", null, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                    new String(c, 0, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        tryCatch("  null, 1, 2", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                    new String((char []) null, 1, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        tryCatch("  c, -1, 4", IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                 new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                         public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                             new String(c, -1, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                         }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        tryCatch("  c, 1, -1", IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                 new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                         public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                             new String(c, 1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                         }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        tryCatch("  c, c.lengh + 1, 1", IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                 new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                         public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                             new String(c, c.length + 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                         }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        tryCatch("  c, 0, c.length + 1", IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                 new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                         public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                             new String(c, 0, c.length + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                         }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private static void byteArrayHiOffCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        System.out.println("String(byte ascii[], int hibyte, int offset, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                           + "int count)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        tryCatch("  b, 0, 0, b.length", null, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    System.out.println(new String(b, 0, 0, b.length));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        tryCatch("  b, -1, 4, 4", null, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    new String(b, -1, 4, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        tryCatch("  null, 0, 0, 0", NullPointerException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                 new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                         public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                             new String((byte[]) null, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                         }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        tryCatch("  b, 0, -1, r", IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                 new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                         public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                             new String(b, 0, -1, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                         }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        tryCatch("  b, 0, 4, -1", IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                 new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                         public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                             new String(b, 0, 4, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                         }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        tryCatch("  b, 0, b.length + 1, 1", IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                 new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                         public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                             new String(b, 0, b.length + 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                         }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        tryCatch("  b, 0, 0, b.length + 1", IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                 new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                         public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                             new String(b, 0, 0, b.length + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                         }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    private static void byteArrayHi() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        System.out.println("String(byte ascii[], int hibyte)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        tryCatch("  b, 0", null, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    new String(b, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        tryCatch("  null, 0", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    new String((byte []) null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    private static void byteArrayOffLengthCharset0(String s, Class ex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                                   byte [] b, int off,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                                                   int len, Object cs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        Throwable t = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            if (cs instanceof String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                new String(b, off, len, (String)cs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            else // (cs instanceof Charset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                new String(b, off, len, (Charset)cs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        } catch (Throwable x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            if (ex.isAssignableFrom(x.getClass()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                t = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                x.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if ((t == null) && (ex != null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            fail(ex, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            pass(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    private static void byteArrayOffLengthCharsetName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        System.out.println("String(byte bytes[], int offset, int length, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                           + "String charsetName)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        System.out.println("  throws UnsupportedEncodingException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        String enc = "UTF-8";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        byteArrayOffLengthCharset0("  b, 0, 0," + enc, null, b, 0, 0, enc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        byteArrayOffLengthCharset0("  null, 0, 0," + enc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                                   NullPointerException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                                   (byte []) null, 0, 0, enc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        byteArrayOffLengthCharset0("  b, -1, 0, " + enc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                                   IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                                   b, -1, 0, enc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        byteArrayOffLengthCharset0("  b, 0, -1, " + enc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                                   IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                                   b, 0, -1, enc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        byteArrayOffLengthCharset0("  b, b.length + 1, 1, " + enc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                   IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                                   b, b.length + 1, 1, enc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        byteArrayOffLengthCharset0("  b, 0, b.length + 1 " + enc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                                   IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                                   b, 0, b.length + 1, enc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        byteArrayOffLengthCharset0("  b, -1, 0, null",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                                   NullPointerException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                                   b, -1, 0, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        byteArrayOffLengthCharset0("  b, 0, b.length, foo",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                                   UnsupportedEncodingException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                                   b, 0, b.length, "foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    private static void byteArrayOffLengthCharset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        System.out.println("String(byte bytes[], int offset, int length, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                           + "Charset charset)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        Charset cs = Charset.forName("UTF-16BE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        byteArrayOffLengthCharset0("  b, 0, 0," + cs, null, b, 0, 0, cs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        byteArrayOffLengthCharset0("  null, 0, 0," + cs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                                   NullPointerException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                                   (byte []) null, 0, 0, cs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        byteArrayOffLengthCharset0("  b, -1, 0, " + cs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                                   IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                   b, -1, 0, cs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        byteArrayOffLengthCharset0("  b, 0, -1, " + cs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                   IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                                   b, 0, -1, cs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        byteArrayOffLengthCharset0("  b, b.length + 1, 1, " + cs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                                   IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                   b, b.length + 1, 1, cs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        byteArrayOffLengthCharset0("  b, 0, b.length + 1 " + cs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                                   IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                                   b, 0, b.length + 1, cs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        byteArrayOffLengthCharset0("  b, -1, 0, null",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                                   NullPointerException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                   b, -1, 0, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    private static void byteArrayCharset0(String s, Class ex, byte [] b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                                          Object cs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        Throwable t = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            if (cs instanceof String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                new String(b, (String)cs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            else // (cs instanceof Charset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                new String(b, (Charset)cs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        } catch (Throwable x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            if (ex.isAssignableFrom(x.getClass()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                t = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                x.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        if ((t == null) && (ex != null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            fail(ex, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            pass(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    private static void byteArrayCharsetName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        System.out.println("String(byte bytes[], String charsetName)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        System.out.println("  throws UnsupportedEncodingException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        String enc = "US-ASCII";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        byteArrayCharset0("  b, " + enc, null, b, enc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        byteArrayCharset0("  null, " + enc, NullPointerException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                          (byte []) null, enc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        byteArrayCharset0("  b, null", NullPointerException.class, b, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        byteArrayCharset0("  null, null", NullPointerException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                          (byte []) null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        byteArrayCharset0("  b, bar", UnsupportedEncodingException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                          b, "bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    private static void byteArrayCharset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        System.out.println("String(byte bytes[], Charset charset)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        Charset cs = Charset.forName("ISO-8859-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        byteArrayCharset0("  b, " + cs, null, b, cs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        byteArrayCharset0("  null, " + cs, NullPointerException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                          (byte []) null, cs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        byteArrayCharset0("  b, null", NullPointerException.class, b, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        byteArrayCharset0("  null, null", NullPointerException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                          (byte []) null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    private static void byteArrayOffLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        System.out.println("String(byte bytes[], int offset, int length)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        tryCatch("  b, 0, b.length", null, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    new String(b, 0, b.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        tryCatch("  null, 0, 0", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    new String((byte []) null, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        tryCatch("  b, -1, b.length", IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                 new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                         public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                             new String(b, -1, b.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                         }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        tryCatch("  b, 0, -1", IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                 new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                         public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                             new String(b, 0, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                         }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        tryCatch("  b, b.length + 1, 1", IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                 new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                         public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                             new String(b, b.length + 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                         }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        tryCatch("  b, 0, b.length", IndexOutOfBoundsException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                 new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                         public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                             new String(b, 0, b.length + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                         }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    private static void byteArray() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        System.out.println("String(byte bytes[])");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        tryCatch("  b", null, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    new String(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                    new String((byte []) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    private static void stringBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        System.out.println("String(StringBuffer buffer)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        tryCatch("  \"bar\"", null, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                    new String(new StringBuffer("bar"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    new String((StringBuffer) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    // -- Methods --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        private static void getChars() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        System.out.println("getChars.(int srcBegin, int srcEnd, char dst[], "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                           + " int dstBegin");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    "foo".getChars(1, 2, null, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    private static void getBytes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        System.out.println("getChars.(int srcBegin, int srcEnd, char dst[], "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                           + " int dstBegin");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        tryCatch("  1, 2, null, 1", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    "foo".getBytes(1, 2, null, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        System.out.println("getBytes.(String charsetName)"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                           + " throws UnsupportedEncodingException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                        "foo".getBytes((String)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    } catch (UnsupportedEncodingException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                        throw new RuntimeException(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        System.out.println("getBytes.(Charset charset)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                    "foo".getBytes((Charset)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    private static void contentEquals() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        System.out.println("contentEquals(StringBuffer sb)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                    "foo".contentEquals(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    private static void compareTo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        System.out.println("compareTo(String anotherString)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        tryCatch("  (String) null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    "foo".compareTo((String) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        /* 4830291 (javac generics bug) causes this test to fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        System.out.println("compareTo(Object o)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        tryCatch("  (Object) null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    "foo".compareTo((Object) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    private static void compareToIgnoreCase() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        System.out.println("compareToIgnoreCase(String anotherString)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                    "foo".compareToIgnoreCase((String) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    private static void regionMatches() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        System.out.println("regionMatches(int toffset, String other,"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                           + " int ooffset, int len)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        tryCatch("  1, null, 1, 1", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                    "foo".regionMatches(1, null, 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        System.out.println("regionMatches(boolean ignore, int toffset,"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                           + " String other, int ooffset, int len)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        tryCatch("  true, 1, null, 1, 1", NullPointerException.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                 new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                         public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                             "foo".regionMatches(true, 1, null, 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                         }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    private static void startsWith() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        System.out.println("startsWith(String prefix, int toffset)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        tryCatch("  null, 1", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                    "foo".startsWith(null, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        System.out.println("startsWith(String prefix)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                    "foo".startsWith(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    private static void endsWith() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        System.out.println("endsWith(String suffix)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    "foo".endsWith(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    private static void indexOf() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        System.out.println("indexOf(String str)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    "foo".indexOf(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        System.out.println("indexOf(String str, int fromIndex)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        tryCatch("  null, 1", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    "foo".indexOf(null, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    private static void lastIndexOf() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        System.out.println("lastIndexOf(String str)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                    "foo".lastIndexOf(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        System.out.println("lastIndexOf(String str, int fromIndex)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        tryCatch("  null, 1", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                    "foo".lastIndexOf(null, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    private static void concat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        System.out.println("concat(String str)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                    "foo".concat(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    private static void matches() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        System.out.println("matches(String regex)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                    "foo".matches(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    private static void replaceFirst() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        System.out.println("replaceFirst(String regex, String replacement)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        tryCatch("  \".\", null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                    "foo".replaceFirst(".", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        tryCatch("  null, \"-\"", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    "foo".replaceFirst(null, "-");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    private static void replaceAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        System.out.println("replaceAll(String regex, String replacement)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        tryCatch("  \".\", null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                    "foo".replaceAll(".", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        tryCatch("  null, \"-\"", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                    "foo".replaceAll(null, "-");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    private static void split() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        System.out.println("split(String regex, int limit)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        tryCatch("  null, 1", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    "foo".split(null, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        System.out.println("split(String regex, int limit)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    "foo".split(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    private static void toLowerCase() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        System.out.println("toLowerCase(Locale locale)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                    "foo".toLowerCase(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    private static void toUpperCase() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        System.out.println("toUpperCase(Locale locale)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                    "foo".toUpperCase(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    private static void valueOf() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        System.out.println("valueOf(Object obj)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        tryCatch("  null", null, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                    String.valueOf((Object) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        System.out.println("valueOf(char data[])");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                    String.valueOf((char []) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        System.out.println("valueOf(char data[], int offset, int count)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        tryCatch("  null, 1, 2", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                    String.valueOf((char []) null, 1, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    private static void copyValueOf() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        System.out.println("copyValueOf(char data[], int offset, int count)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        tryCatch("  null, 1, 2", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                    "foo".copyValueOf((char []) null, 1, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        System.out.println("copyVlueOf(char data[])");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        tryCatch("  null", NullPointerException.class, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                    String.copyValueOf((char []) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    public static void main(String [] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        // -- Constructors --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        noArgs();             // String()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        string();             // String(String original)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        charArray();          // String(char value[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        charArrayOffCount();  // String(char value[], int offset, int count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        // String(byte ascii[], int hibyte, int offset, int count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        byteArrayHiOffCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        byteArrayHi();        // String(byte ascii[], int hibyte)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        // String(byte bytes[], int offset, int length, String charsetName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        //   throws UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        byteArrayOffLengthCharsetName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        // String(byte bytes[], int offset, int length, Charset charset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        byteArrayOffLengthCharset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        // String(byte bytes[], String charsetName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        //   throws UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        byteArrayCharsetName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        // String(byte bytes[], Charset charset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        byteArrayCharset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        byteArrayOffLength(); // String(byte bytes[], int offset, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        byteArray();          // String(byte bytes[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        stringBuffer();       // String(StringBuffer buffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        // -- Methods --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        getChars();           // getChars(int, int. char [], int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        getBytes();           // getBytes(int, int, byte [], int),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                              //   getBytes(Locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                              //   getBytes(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                              //   getBytes(Charset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        contentEquals();      // contentEquals(StringBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        compareTo();          // compareTo(String), compareTo(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        compareToIgnoreCase();// compareToIgnoreCase(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        regionMatches();      // regionMatches(int, String, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                              //   regionMatches(boolean, int, String, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        startsWith();         // startsWith(String, int), startsWith(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        endsWith();           // endsWith(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        indexOf();            // indexOf(String), indexOf(String, int),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        lastIndexOf();        // lastIndexOf(String), lastIndexOf(String, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        concat();             // concat(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        matches();            // matches(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        replaceFirst();       // replaceFirst(String, String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        replaceAll();         // replaceAll(String, String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        split();              // split(String, int), split(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        toLowerCase();        // toLowerCase(Locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        toUpperCase();        // toUpperCase(Locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        valueOf();            // valueOf(Object), valueOf(char []),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                              //   valueOf(char [], int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        copyValueOf();        // copyValueOf(char [], int, int),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                              //    copyValueOf(char [])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        if (!ok)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            throw new RuntimeException("Some tests FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            System.out.println("All tests PASSED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
}