Skip to content

Commit af1de3a

Browse files
jmeznaTFaga
authored andcommitted
in ConfigBundleInterceptor, do not set nested object, if no keys for the nested class exist
1 parent 9059928 commit af1de3a

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/interceptors/ConfigBundleInterceptor.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,14 @@ public Object loadConfiguration(InvocationContext ic) throws Exception {
8282
* @param keyPrefix a prefix for generating key names
8383
* @param processedClassRelations class pairs that have already been processed (for cycle detection)
8484
* @param watchAllFields if true, enable watch on all fields
85+
* @return returns true, if at least one field was successfully populated from configuration sources
8586
* @throws Exception
8687
*/
87-
private void processConfigBundleBeanSetters(Object target, Class targetClass, String keyPrefix, Map<Class, Class>
88+
private boolean processConfigBundleBeanSetters(Object target, Class targetClass, String keyPrefix, Map<Class, Class>
8889
processedClassRelations, boolean watchAllFields) throws Exception {
8990

91+
boolean isConfigBundleEmpty = true;
92+
9093
// invoke setters
9194
for (Method method : targetClass.getMethods()) {
9295

@@ -102,7 +105,7 @@ private void processConfigBundleBeanSetters(Object target, Class targetClass, St
102105
}
103106

104107
// watch nested class or list if all fields in the bean are annotated with watch or if a field is
105-
// annnotated with watch
108+
// annotated with watch
106109
boolean watchNestedClass = watchAllFields;
107110
if (watchNestedClass == false) {
108111
if (fieldAnnotation != null) {
@@ -117,6 +120,7 @@ private void processConfigBundleBeanSetters(Object target, Class targetClass, St
117120
.getName(), keyPrefix));
118121

119122
if (value.isPresent()) {
123+
isConfigBundleEmpty = false;
120124
method.invoke(target, value.get());
121125
}
122126

@@ -164,7 +168,7 @@ private void processConfigBundleBeanSetters(Object target, Class targetClass, St
164168
}
165169
}
166170
}
167-
171+
return isConfigBundleEmpty;
168172
}
169173

170174
/**
@@ -227,8 +231,12 @@ private Object processNestedObject(Class targetClass, Method method, Class param
227231
key += "[" + arrayIndex + "]";
228232
}
229233

230-
processConfigBundleBeanSetters(nestedTarget, nestedTargetClass, key, processedClassRelations,
231-
watchAllFields);
234+
boolean isEmpty = processConfigBundleBeanSetters(nestedTarget, nestedTargetClass, key,
235+
processedClassRelations, watchAllFields);
236+
237+
if (isEmpty) {
238+
return null;
239+
}
232240
}
233241

234242
return nestedTarget;

0 commit comments

Comments
 (0)