in archaius2-core/src/main/java/com/netflix/archaius/ConfigProxyFactory.java [365:394]
private <PT> Function<Object[], ?> defaultValueSupplierForMethod(Class<PT> proxyObjectType, Method m, Type returnType, PT proxyObject, String propName) {
if (m.getAnnotation(DefaultValue.class) != null) {
// The method has a @DefaultValue annotation. Decode the string from there and return that.
return createAnnotatedMethodSupplier(m, m.getGenericReturnType(), config, decoder);
}
if (m.isDefault()) {
// The method has a default implementation in the interface. Obtain the default value by calling that implementation.
return createDefaultMethodSupplier(m, proxyObjectType, proxyObject);
}
// No default value available.
// For collections, return an empty
if (knownCollections.containsKey(returnType)) {
return knownCollections.get(returnType);
}
// For primitive return types, our historical behavior of returning a null causes an NPE with no message and an
// obscure trace. Instead of that we now use a fake supplier that will still throw the NPE, but adds a message to it.
if (returnType instanceof Class && ((Class<?>) returnType).isPrimitive()) {
return (ignored) -> {
String msg = String.format("Property '%s' is not set or has an invalid value and method %s.%s does not define a default value",
propName, proxyObjectType.getName(), m.getName());
throw new NullPointerException(msg);
};
}
// For any other return type return nulls.
return (ignored) -> null;
}