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
if (constructorParameterKeys.contains(fieldKey)) {
58
+
field.isAccessible =true
59
+
field.set(target, injector.getInstance(fieldKey))
60
+
constructorParameterKeys.remove(fieldKey)
61
+
log.debug("Injecting ${field.name} after deserialisation")
62
+
} else {
63
+
unResolvedFieldKeys[field] = fieldKey
64
+
log.debug("${field.name} is not a Guice injected field, no injection after deserialisation")
65
+
}
66
+
}
67
+
68
+
}
69
+
70
+
privatefuncreateFieldKey(field:Field): Key<*> {
71
+
val genericType = field.genericType
72
+
val fieldAnnotations = field.declaredAnnotations
73
+
for (annotationin fieldAnnotations) {
74
+
val annotationInterfaces = annotation.javaClass.annotatedInterfaces
75
+
for (annInterface in annotationInterfaces) {
76
+
val annotationType = annInterface.type
77
+
if ((annotationType asClass<*>).isAnnotationPresent(BindingAnnotation::class.java)) {
78
+
log.debug("$annotationType is a binding annotation")
79
+
returnKey.get(genericType, annotation)
80
+
} else {
81
+
log.debug("$annotationType is not a binding annotation, and is therefore ignored")
82
+
}
83
+
}
84
+
}
85
+
log.debug("Field ${field.name} has no binding annotations")
86
+
returnKey.get(genericType)
87
+
}
88
+
89
+
90
+
/**
91
+
* Execute this method at the end of readObject() to make sure there are no transient fields left with value still at null
92
+
*/
93
+
overridefuncheckForNullTransients() {
94
+
// we can't just use unresolvedFieldKeys, because the developer could set a transient to null after injectTransientFields was invoked
95
+
val candidateFields = collectCandidateFields()
96
+
if (candidateFields.isEmpty()) {
97
+
// all transients have been populated
98
+
log.debug("Deserialization complete, all fields resolved")
99
+
if (unResolvedFieldKeys.isNotEmpty()) {
100
+
// simply means that user code filled in a field
101
+
log.debug("These fields were populated by user code: $unResolvedFieldKeys")
102
+
}
103
+
if (constructorParameterKeys.isNotEmpty()) {
104
+
// somehow all the fields have been populated but not all the constructor params have been used. Warn the developer
105
+
log.warn("All transient fields have been populated after deserialization, but these constructor parameters were not used: $constructorParameterKeys. This can occur if you have populated a Guice injected transient field without using SerializationSupport, or you have excluded a Guice injected transient field, or you have missed an annotation from a subclass constructor parameter")
106
+
}
107
+
} else {
108
+
// a field has been missed - throw exception, suggest exclusion
109
+
val nullFieldNames = mutableListOf<String>()
110
+
for (field in candidateFields) {
111
+
nullFieldNames.add(field.name)
112
+
}
113
+
throwSerializationSupportException("One or more transient fields is still null after deserialization. If this is required state, add them to the 'exclusions' parameter to prevent this exception. Null fields are: $nullFieldNames")
0 commit comments