The symptom is a NegativeArraySizeException thrown by a newly introduced
method, filterFields():
java.lang.NegativeArraySizeException
at sun.reflect.Reflection.filterFields(Reflection.java:235)
at java.lang.Class.privateGetDeclaredFields(Class.java:1884)
at java.lang.Class.privateGetPublicFields(Class.java:1916)
at java.lang.Class.getFields(Class.java:1007)
at
com.bea.util.jam.internal.reflect.ReflectClassBuilder.populate(ReflectCl
assBuilder.java:128)
A comment on this problem:
>So I looked at the Sun source. filterFields is new in b49 and looks
like this (the line in question is where newFields gets allocated):
>
> public static Field[] filterFields(Class containingClass,
> Field[] fields) {
> if (fieldFilterMap == null) {
> // Bootstrapping
> return fields;
> }
> String[] filteredFieldNames = (String[])
fieldFilterMap.get(containingClass);
> if (filteredFieldNames == null) {
> return fields;
> }
> Field[] newFields = new Field[fields.length -
filteredFieldNames.length];
> int destIdx = 0;
> for (int srcIdx = 0; srcIdx < fields.length; srcIdx++) {
> boolean shouldSkip = false;
> Field field = fields[srcIdx];
> for (int tmp = 0; tmp < filteredFieldNames.length; tmp++) {
> if (field.getName() == filteredFieldNames[tmp]) {
> shouldSkip = true;
> break;
> }
> }
> if (!shouldSkip) {
> newFields[destIdx++] = field;
> }
> }
> return newFields;
> }
>
>Clearly there are more filtered fields than fields which seems a little
impossible (and a clear bug).
>
test case:
public class Repro {
public static void main(String[] args) throws ClassNotFoundException {
Class c=Class.forName("sun.reflect.ConstantPool");
java.lang.reflect.Field[] f=c.getFields();
System.out.println("Fields Found: " + f.length);
}
}
Try this against build 49 or 50, and you'll get:
Exception in thread "main" java.lang.NegativeArraySizeException
at sun.reflect.Reflection.filterFields(Reflection.java:235)
at java.lang.Class.privateGetDeclaredFields(Class.java:1884)
at java.lang.Class.privateGetPublicFields(Class.java:1916)
at java.lang.Class.getFields(Class.java:1007)
at Repro.main(Repro.java:5)