Skip to content

The order of JField between different runs聽#154

Closed

Description

@bowenspeaksoul

馃摑 Overall Description

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.

鈿欙笍 Tai-e Arguments

No response

馃摐 Tai-e Log

No response

鈩癸笍 Additional Information

No response

Activity

  1. self-assigned this
    on May 17, 2025
  2. added theissue type on May 17, 2025
  3. jjppp commented on May 17, 2025

    @jjppp
    Member

    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.

  4. removed theissue type on May 23, 2025
  5. cs-cat commented on May 23, 2025

    @cs-cat
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions