Skip to content

Commit

Permalink
Avoid null type, derive from provider type params or fallback to Object.
Browse files Browse the repository at this point in the history
  • Loading branch information
sdedic committed Dec 8, 2023
1 parent ca7b58b commit f1e40ae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ public ValueAndType findPropertyValueInternal(String propName, Object val) {
return new ValueAndType(provided.getType());
}
if (isFixedValue("property " + propName, etv)) {
return new ValueAndType(provided.getType(), etv.getFixedValue());
Object fixed = etv.getFixedValue();
Class t = provided.getType();
if (t == null && fixed != null) {
t = fixed.getClass();
}
return new ValueAndType(t, fixed);
} else {
return new ValueAndType(provided.getType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,10 +718,18 @@ private void inspectObjectAndValues0(Class clazz, Object object, String prefix,
if (Provider.class.isAssignableFrom(t)) {
ValueAndType vt = adapter.findPropertyValueInternal(propName, value);
if (vt != null) {
t = vt.type;
if (vt.value.isPresent()) {
value = vt.value.get();
}
if (vt.type != null) {
t = vt.type;
} else if (typeParameters != null && !typeParameters.isEmpty() && (typeParameters.get(0) instanceof Class)) {
// derive the type from the provider's type parameter
t = (Class)typeParameters.get(0);
} else {
// null value with an unspecified type from the provider
t = Object.class;
}
}
}
} catch (RuntimeException ex) {
Expand Down Expand Up @@ -940,6 +948,9 @@ private static String objectToString(Object o) {
}

private static Class findNonDecoratedClass(Class clazz) {
if (clazz == null || clazz.isInterface()) {
return clazz;
}
while (clazz != Object.class && (clazz.getModifiers() & 0x1000 /* Modifiers.SYNTHETIC */) > 0) {
clazz = clazz.getSuperclass();
}
Expand Down

0 comments on commit f1e40ae

Please sign in to comment.