langtools/test/tools/javac/boxing/Boxing1.java
author mcimadamore
Thu, 03 Feb 2011 09:38:19 +0000
changeset 8239 d2c934e951e2
parent 5520 86e4b9a9da40
permissions -rw-r--r--
7014715: javac returns different error code for certain failure(s) Summary: javac silently crashes when emitting certain kinds of resolution diagnostics Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2985
diff changeset
     2
 * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2985
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2985
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2985
diff changeset
    21
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
 * @test
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
 * @bug 4869233 4872709 4868735 4921949 4921209 4965701 4934916 4975565 4974939
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
 * @summary Boxing/unboxing positive unit and regression tests
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
 * @author gafter
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
public class Boxing1 {
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
    static Boolean _Boolean = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
    static boolean _boolean = _Boolean;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
    static Byte _Byte = (byte)3;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
    static byte _byte = _Byte;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
    static Character _Character = 'a';
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
    static char _char = _Character;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
    static Short _Short = (short)4;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
    static short _short = _Short;
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
    static Integer _Integer = 5;
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    static int _int = _Integer;
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    static Long _Long = 12L;
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    static long _long = _Long;
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    static Float _Float = 1.2f;
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    static float _float = _Float;
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    static Double _Double = 1.34;
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    static double _double = _Double;
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    public static void main(String[] args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
        _Double = _Integer + _Integer + 0.0d;
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
        if (_Double != 10) throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
        _Integer = 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
        _float = _Integer;
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
        if (_float != 2.0f) throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
        _int = 12;
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
        _Float = _int + 0.0f;
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
        if (_Float != 12.0f) throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        _Integer = 8;
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        _float = (float)_Integer;
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
        if (_float != 8.0f) throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
        _int = 9;
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        _Float = (Float)(_int + 0.0f);
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
        if (_Float != 9.0f) throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        if (_Boolean) ; else throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        if (!_Boolean) throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
        if (_Integer >= _Long) throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        _Character = 'a';
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        String s1 = ("_" + _Character + "_").intern();
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        if (s1 != "_a_") throw new Error(s1);
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        /* assignment operators don't work; see 4921209 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        if (_Integer++ != 8) throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        if (_Integer++ != 9) throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        if (++_Integer != 11) throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
        if ((_Integer += 3) != 14) throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        if ((_Integer -= 3) != 11) throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
        Integer i = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        i = i + 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
        i += 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
        if (i != 4) throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        int j = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        j += i;
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        if (j != 4) throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        Integer a[] = new Integer[1];
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        a[0] = 3;
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        a[0] += 3;
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        if (a[0] != 6) throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        Froobie x = new Froobie();
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
        Froobie y = new Froobie();
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
        x.next = y;
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        x.next.i = 4;
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
        x.next.i += 4;
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        if (--x.next.i != 7) throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        if (x.next.i-- != 7) throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        if (x.next.i != 6) throw new Error();
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        boxIndex();
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        boxArray();
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    static void boxIndex() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        String[] a = { "hello", "world" };
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        Integer i = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        System.out.println(a[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    static void boxArray() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
        Integer[] a2 = { 0, 1, 2, 3 };
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        for (int i : a2)
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
            System.out.println(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    static class Froobie {
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
        Froobie next = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
        Integer i = 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    static class Scott {
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        Integer i[];
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        Integer j[];
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        Integer k;
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
        int q = i[j[k]]++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    class T4974939 {
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        void f() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
            Byte b = 12;
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
            Byte c = 'a';
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
            Short s = 'b';
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
            Short t = 12;
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
            Character d = 12;
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
}