You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the following loop while using tai-e, where the logic depends on the order in which JField appears in the loop (that is, I assign an index to these fields). However, I found that the order of JField appearances seems inconsistent across different runs.
JClass jclass = ...;
for (JField field : jclass.getDeclaredFields()) {
// some code that relies on the order of these fields
}
My question is whether this behavior is expected or a potential bug? Thanks a lot!
馃幆 Expected Behavior
N/A
馃悰 Current Behavior
N/A
馃攧 Reproducible Example
My issue occurs in a class with a very large number of fields.
A possible cause analysis: jclass.getDeclaredFields() returns a set. The hashcodes of same JField objects change across different analysis sessions. This causes the order of JFields to vary when iterating over a HashSet.
The JField class uses Java's default hashCode implementation, which returns a pseudo-random value that depends on the timing of the hashCode invocation. Since IR construction is multithreaded by default, the timing at which the JVM generates the hashCode for each JField is nondeterministic. As a result, the JField object corresponding to the same field may have different hash codes in different analysis sessions.
Please continue to track this in #206 going forward.
Activity
jjppp commentedon May 17, 2025
Could you share the jar file you're analyzing and the configuration of Tai-e?
For workaround you can store the fields in your own list and sort it according to your indices.
cs-cat commentedon May 23, 2025
A possible cause analysis:
jclass.getDeclaredFields()returns a set. The hashcodes of same JField objects change across different analysis sessions. This causes the order of JFields to vary when iterating over a HashSet.The JField class uses Java's default hashCode implementation, which returns a pseudo-random value that depends on the timing of the hashCode invocation. Since IR construction is multithreaded by default, the timing at which the JVM generates the hashCode for each JField is nondeterministic. As a result, the JField object corresponding to the same field may have different hash codes in different analysis sessions.
Please continue to track this in #206 going forward.