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