1 import java.io.IOException; 2 class Blort { 3 private static void arrayCopyTest(int k) { 4 // A local variable assigned from an argument 5 int j = k; 6 // These two locals are defined once and used multiple times 7 String[] stringArray = new String[8]; 8 Object[] objectArray = new Object[8]; 9 // Should cause another move to be inserted 10 Object anotherOne = objectArray; 11 12 if (anotherOne != null) { 13 System.out.println("foo"); 14 } 15 16 // "i" is used in a loop 17 for (int i = 0; i < stringArray.length; i++) 18 stringArray[i] = new String(Integer.toString(i)); 19 20 System.out.println("string -> object"); 21 System.arraycopy(stringArray, 0, objectArray, 0, stringArray.length); 22 System.out.println("object -> string"); 23 System.arraycopy(objectArray, 0, stringArray, 0, stringArray.length); 24 System.out.println("object -> string (modified)"); 25 objectArray[4] = new Object(); 26 try { 27 System.arraycopy(objectArray, 0, stringArray, 0,stringArray.length); 28 } catch (ArrayStoreException ase) { 29 // "ase" is an unused local which still must be preserved 30 System.out.println("caught ArrayStoreException (expected)"); 31 } 32 } 33 34 private void testConstructor() { 35 Blort foo = null; 36 try { 37 foo = new Blort(); 38 } catch (Exception ex) { 39 } 40 System.err.println(foo); 41 } 42 /** 43 * Stolen from 44 * java/android/org/apache/http/impl/io/AbstractMessageParser.java 45 * Simplified. 46 * 47 * Checks to see that local variable assignment is preserved through 48 * phi's. The key component here is the assignment of previous = current. 49 */ 50 public static void parseHeaderGroup( 51 final Object headGroup, 52 final Object inbuffer, 53 int maxHeaderCount, 54 int maxLineLen) 55 throws IOException { 56 57 StringBuilder current = null; 58 StringBuilder previous = null; 59 for (;;) { 60 if (current == null) { 61 current = new StringBuilder(64); 62 } else { 63 current.length(); 64 } 65 int l = inbuffer.hashCode(); 66 if (l == -1 || current.length() < 1) { 67 break; 68 } 69 70 if ((current.charAt(0) == ' ' || current.charAt(0) == '\t') && previous != null) { 71 int i = 0; 72 while (i < current.length()) { 73 char ch = current.charAt(i); 74 if (ch != ' ' && ch != '\t') { 75 break; 76 } 77 i++; 78 } 79 if (maxLineLen > 0 80 && previous.length() + 1 + current.length() - i > maxLineLen) { 81 throw new IOException("Maximum line length limit exceeded"); 82 } 83 previous.append(' '); 84 previous.append(current, i, current.length() - i); 85 } else { 86 previous = current; 87 current = null; 88 } 89 if (maxHeaderCount > 0) { 90 throw new IOException("Maximum header count exceeded"); 91 } 92 } 93 } 94 } 95