apache/maven · warning

Invalid value reference types '{}', using defaults

Error message

Invalid value reference types '{}', using defaults

What it means

Same enum-validation path as the key variant, applied to the value reference type of the internal cache: the user property (Constants.MAVEN_CACHE_VALUE_REFS, which in this codebase resolves to the same 'maven.cache.keyValueRefs' name) failed Cache.ReferenceType.valueOf() and valueRefType remains null, so the default value reference type is used. The warning names the offending string verbatim.

Source

Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/cache/CacheConfigurationResolver.java:77

        Cache.ReferenceType keyRefType = null;
        String keyRefsString = session.getUserProperties().get(Constants.MAVEN_CACHE_KEY_REFS);
        if (keyRefsString != null && !keyRefsString.trim().isEmpty()) {
            try {
                keyRefType = Cache.ReferenceType.valueOf(keyRefsString.trim().toUpperCase());
            } catch (IllegalArgumentException e) {
                LOGGER.warn("Invalid key reference types '{}', using defaults", keyRefsString);
            }
        }

        // Check for value reference type configuration
        Cache.ReferenceType valueRefType = null;
        String valueRefsString = session.getUserProperties().get(Constants.MAVEN_CACHE_VALUE_REFS);
        if (valueRefsString != null && !valueRefsString.trim().isEmpty()) {
            try {
                valueRefType =
                        Cache.ReferenceType.valueOf(valueRefsString.trim().toUpperCase());
            } catch (IllegalArgumentException e) {
                LOGGER.warn("Invalid value reference types '{}', using defaults", valueRefsString);
            }
        }

        // Get user-defined configuration
        String configString = session.getUserProperties().get(Constants.MAVEN_CACHE_CONFIG_PROPERTY);
        if (configString == null || configString.trim().isEmpty()) {
            // No user configuration, use legacy behavior or defaults
            if (legacyRetention != null) {
                CacheConfig config = new CacheConfig(
                        legacyRetention, getDefaultReferenceType(legacyRetention), keyRefType, valueRefType);
                return config;
            }
            if (keyRefType != null && valueRefType != null) {
                return new CacheConfig(
                        CacheConfig.DEFAULT.scope(), CacheConfig.DEFAULT.referenceType(), keyRefType, valueRefType);
            }
            return CacheConfig.DEFAULT;
        }

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Use only soft, hard, weak, or none for the reference-type property
  2. Validate the value before committing .mvn/maven.config changes by running any mvn command and checking for this warning
  3. Remove the property to fall back to defaults if the tuning is not required

Example fix

# before
export MAVEN_OPTS="$MAVEN_OPTS -Dmaven.cache.keyValueRefs=strong"

# after
export MAVEN_OPTS="$MAVEN_OPTS -Dmaven.cache.keyValueRefs=hard"
Defensive patterns

Strategy: validation

Validate before calling

// Same whitelist guard for the value side
static final Set<String> VALID_REFS = Set.of("SOFT", "HARD", "WEAK", "NONE");
String refs = props.getProperty("maven.cache.keyValueRefs");
if (refs != null && !VALID_REFS.contains(refs.trim().toUpperCase(Locale.ROOT))) {
    throw new IllegalArgumentException("reference type must be soft|hard|weak|none: " + refs);
}

Type guard

boolean isValidReferenceType(String s) {
    return s != null && Set.of("soft", "hard", "weak", "none")
            .contains(s.trim().toLowerCase(Locale.ROOT));
}

Prevention

When it happens

Trigger: Setting the cache reference-type user property to anything that is not one of SOFT/HARD/WEAK/NONE after trim+uppercase, e.g. 'strong', 'phantom', 'Soft,' or a locale-formatted string.

Common situations: Misremembered GC terminology ('strong' instead of 'hard', 'phantom' instead of 'weak'); values copied between key and value config keys with an edit error; team-wide .mvn/maven.config with a stale value after a Maven upgrade changed the accepted set.

Related errors


AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21). Data as JSON: /api/errors/e7547e16f9907fd0. Report an issue: GitHub.