Currently Structure.setFieldOrder() indicates that it only needs to be invoked on platforms where "field order as returned by Class.getFields() is not predictable." But in fact, field order is not guaranteed to be predictable on any platform.
The specification for Class.getFields() explicitly states "The elements in the array returned are not sorted and are not in any particular order." It's a mistake to imply that users may skip this required step. Look at what happened in Java7. Class.getDeclaredMethods() used to return methods in a predictable order but it no longer does: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7023180
We should require users to invoke this method from now on, otherwise their applications are likely to break in the near future.
I agree. Initially field order was left out because all desktop VMs empirically had predictable field order, but now given the range of VMs available it's better to stick to the spec.
Currently working on this one. Still have a few outstanding testsuite failures due to the (now) required field order initialization.
I propose making setFieldOrder() final, and getFieldOrder() abstract. This will flag 95% of code that will need modification in order to properly declare field order. Structures subclassed more than once would need special attention (since the superclass having defined the abstract method would hide the absence of additional field order for the subclass).
This would warrant a version bump to 3.5, for the introduced incompatibility.
See corresponding branch, explicit-structure-field-order.
address issue #84
On a related note, I just ran across this exception (on the Android branch):
The problem is this:
I reviewed your commit and it looks good. Is there any reason you didn't merge these changes into the master and android branches and close this issue?
PS: Do you get notifications when I post comments on your commits as I did here? a947dfd
Applied to master in 2ff4d20.