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