protected T handleMissing()

in src/main/java/org/apache/commons/beanutils2/converters/AbstractConverter.java [333:356]


    protected <T> T handleMissing(final Class<T> type) {
        if (useDefault || type.equals(String.class)) {
            Object value = getDefault(type);
            if (useDefault && value != null && !type.equals(value.getClass())) {
                try {
                    value = convertToType(type, defaultValue);
                } catch (final Throwable t) {
                    throw new ConversionException("Default conversion to " + toString(type) + " failed.", t);
                }
            }
            if (log().isDebugEnabled()) {
                log().debug("    Using default " + (value == null ? "" : toString(value.getClass()) + " ") + "value '" + defaultValue + "'");
            }
            // value is now either null or of the desired target type
            return type.cast(value);
        }

        final ConversionException cex = ConversionException.format("No value specified for '%s'", toString(type));
        if (log().isDebugEnabled()) {
            log().debug("    Throwing ConversionException: " + cex.getMessage());
            log().debug("    " + DEFAULT_CONFIG_MSG);
        }
        throw cex;
    }