1 /* 2 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @summary Confirm that AtomicInteger and AtomicLong are formatted correctly. 27 * @bug 6278616 28 */ 29 30 import java.text.NumberFormat; 31 import java.util.concurrent.atomic.AtomicInteger; 32 import java.util.concurrent.atomic.AtomicLong; 33 34 import java.util.Locale; 35 36 public class Bug6278616 { 37 38 static final int[] ints = { 39 Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE 40 }; 41 42 static final long[] longs = { 43 Long.MIN_VALUE, -1, 0, 1, Long.MAX_VALUE 44 }; 45 46 public static void main(String[] args) { 47 NumberFormat nf = NumberFormat.getInstance(); 48 49 for (int j = 0; j < ints.length; j++) { 50 String s_i = nf.format(new Integer(ints[j])); 51 String s_ai = nf.format(new AtomicInteger(ints[j])); 52 if (!s_i.equals(s_ai)) { 53 throw new RuntimeException("format(AtomicInteger " + s_ai + 54 ") doesn't equal format(Integer " + 55 s_i + ")"); 56 } 57 } 58 59 for (int j = 0; j < longs.length; j++) { 60 String s_l = nf.format(new Long(longs[j])); 61 String s_al = nf.format(new AtomicLong(longs[j])); 62 if (!s_l.equals(s_al)) { 63 throw new RuntimeException("format(AtomicLong " + s_al + 64 ") doesn't equal format(Long " + 65 s_l + ")"); 66 } 67 } 68 } 69 }