Re: Strange JTable issue in Sun's Java code
I get:
java.lang.NegativeArraySizeException
at NullTest.removeEntries(NullTest.java:43)
when I run this.
Maybe another precondition needs checking.
public class Test {
private static int[] a = {};
public static void main(String[] args) {
try {
removeEntries(0,3);
} catch (Exception e) {
e.printStackTrace();
}
}
private static int[] getSizes() {
return new int[]{1,2,3,4,5};
}
/**
* Removes a contiguous group of entries
* from this <code>SizeSequence</code>.
* Note that the values of <code>start</code> and
* <code>length</code> must satisfy the following
* conditions: <code>(0 <= start < getSizes().length)
* AND (length >= 0)</code>. If these conditions are
* not met, the behavior is unspecified and an exception
* may be thrown.
*
* @param start the index of the first entry to be removed
* @param length the number of entries to be removed
*/
public static void removeEntries(int start, int length) {
assert getSizes() != null;
assert 0 <= start;
assert start < getSizes().length;
assert length >= 0;
assert a != null;
int sizes[] = getSizes();
//int end = start + length;
int n = a.length - length;
a = new int[n];
for (int i = 0; i < start; i++) {
a[i] = sizes[i] ;
}
for (int i = start; i < n; i++) {
a[i] = sizes[i+length] ;
}
//setSizes(a);
}