Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

sorting fields for deterministic order #565

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
Expand Down Expand Up @@ -148,7 +150,14 @@ public static <T> Binding<T> create(Class<T> type, boolean mustHaveInjections) {
// Lookup the injectable fields and their corresponding keys.
List<Field> injectedFields = new ArrayList<Field>();
for (Class<?> c = type; c != Object.class; c = c.getSuperclass()) {
for (Field field : c.getDeclaredFields()) {
Field[] fields = c.getDeclaredFields();
Arrays.sort(fields, new Comparator<Object>() {
@Override
public int compare(Object a, Object b) {
return a.toString().compareTo(b.toString());
}
});
for (Field field : fields) {
if (!field.isAnnotationPresent(Inject.class) || Modifier.isStatic(field.getModifiers())) {
continue;
}
Expand Down