Skip to content

The order of JField between different runs #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
BowenZhang-UST opened this issue May 16, 2025 · 2 comments
Open

The order of JField between different runs #154

BowenZhang-UST opened this issue May 16, 2025 · 2 comments
Assignees
Labels

Comments

@BowenZhang-UST
Copy link

📝 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

@jjppp
Copy link
Member

jjppp commented 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.

@zhangt2333 zhangt2333 added the type: bug A general bug label May 23, 2025
@cs-cat
Copy link
Collaborator

cs-cat commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants