1 /*
   2  * Copyright (c) 2011, 2013, 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 <rdar://problem/2208170> JITC problem with arrays (initialization?)
  27  @summary com.apple.junit.java.vm
  28  @run junit ArrayInit_R2208170
  29  */
  30 
  31 import junit.framework.*;
  32 
  33 public class ArrayInit_R2208170 extends TestCase {
  34 
  35     public static Test suite() {
  36         return new TestSuite(ArrayInit_R2208170.class);
  37     }
  38 
  39     public static void main (String[] args) throws RuntimeException {
  40         TestResult tr = junit.textui.TestRunner.run(suite());
  41         if((tr.errorCount() != 0) || (tr.failureCount() != 0)) {
  42             throw new RuntimeException("### Unexpected JUnit errors or failures.");
  43         }
  44     }
  45 
  46    public void testArrayInit() {
  47         R2208170ThingMap    theMap = new R2208170ThingMap();
  48         assertEquals("Array initialization is messed up","(100)", (theMap.getThingRecords())[0].toString());
  49     }
  50 }
  51 
  52 class R2208170ThingMap {
  53     public R2208170ThingRec[]    getThingRecords() {
  54         return mThingList;
  55     }
  56 
  57     R2208170ThingRec    mThingList[] = {
  58         new R2208170ThingRec( 1, 1, new R2208170Thing( "1", new Object[] { new Integer(100) } ) ),
  59         new R2208170ThingRec( 2, 2, new R2208170Thing( "2", new Object[] { new Integer(200) } ) ),
  60         new R2208170ThingRec( 3, 3, new R2208170Thing( "3", new Object[] { new Integer(300) } ) )
  61     };
  62 }
  63 
  64 class R2208170ThingRec {
  65     R2208170Thing    mThing;
  66 
  67     public R2208170ThingRec(
  68             @SuppressWarnings("unused") int inDummy1,
  69             @SuppressWarnings("unused") int inDummy2,
  70             R2208170Thing inThing
  71     ) {
  72         mThing = inThing;
  73     }
  74 
  75     public String    toString()    {
  76         return mThing.toString();
  77     }
  78 }
  79 
  80 class R2208170Thing {
  81     Object[]    mArray;
  82 
  83     public    R2208170Thing(
  84             @SuppressWarnings("unused") String inDummy,
  85             Object[]    inArray
  86     )    {
  87         mArray = inArray;
  88     }
  89 
  90     public String    toString()    {
  91         try {
  92             StringBuffer sbuf = new StringBuffer();
  93             sbuf.append('(');
  94             if (mArray != null) {
  95                 for (int i=0; i<mArray.length; i++) {
  96                     if (i != 0)
  97                         sbuf.append(" ,");
  98                     sbuf.append(mArray[i] != null ? mArray[i].toString() : "null");
  99                 }
 100             }
 101             sbuf.append(')');
 102             return sbuf.toString();
 103         } catch(Exception e) {
 104             return null;
 105         }
 106     }
 107 }