quarkusio/quarkus · error · UnsupportedOperationException

Cannot use `" + methodName + "` method without a default typ

Error message

Cannot use `" + methodName + "` method without a default type configured. Consider using the `" + methodName + "` method accepting the type or configure the default type for the cache " + getName()

What it means

RedisCacheImpl stores values as encoded bytes; to decode on read it needs a value Class (classOfValue), which comes from build-time value-type configuration. The type-less convenience methods (get(key, loader), getAsync, getOrDefault, getOrNull) call enforceDefaultType and fail with UnsupportedOperationException when no default type was configured for the cache.

Source

Thrown at extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheImpl.java:305

    public <K, V> Uni<Void> put(K key, V value) {
        return put(key, new StaticSupplier<>(value));
    }

    @Override
    public <K, V> Uni<Void> put(K key, Supplier<V> supplier) {
        byte[] encodedKey = marshaller.encode(computeActualKey(encodeKey(key)));
        byte[] encodedValue = marshaller.encode(supplier.get());
        return withConnection(new Function<RedisConnection, Uni<Void>>() {
            @Override
            public Uni<Void> apply(RedisConnection connection) {
                return set(connection, encodedKey, encodedValue);
            }
        });
    }

    private void enforceDefaultType(String methodName) {
        if (classOfValue == null) {
            throw new UnsupportedOperationException("Cannot use `" + methodName + "` method without a default type configured. "
                    + "Consider using the `" + methodName
                    + "` method accepting the type or configure the default type for the cache "
                    + getName());
        }
    }

    @Override
    public <K, V> Uni<V> getOrDefault(K key, V defaultValue) {
        enforceDefaultType("getOrDefault");
        return getOrDefault(key, classOfValue, defaultValue);
    }

    @Override
    public <K, V> Uni<V> getOrDefault(K key, Class<V> clazz, V defaultValue) {
        return getOrDefault(key, (Type) clazz, defaultValue);
    }

    @Override

View on GitHub (pinned to e1c734241f)

Solutions

  1. Set quarkus.cache.redis.<cacheName>.value-type=... in configuration so the default type is known
  2. Use the typed API variant: cache.get(key, MyType.class, loader) instead of the untyped get(key, loader)
  3. Add a @CacheResult-annotated method so the value type is inferred at build time
  4. Cast through the typed Cache interface and always pass the value Class explicitly

Example fix

// before
V v = redisCache.get(key, k -> load(k));
// after
V v = redisCache.get(key, MyType.class, k -> load(k));
Defensive patterns

Strategy: validation

Validate before calling

// before using untyped API
if (System.getProperty("quarkus.cache.redis.my-cache.value-type") == null) {
    // use typed API instead
    cache.get(key, MyType.class, loader);
}

Try / catch

try {
    cache.get(key, loader);
} catch (UnsupportedOperationException e) {
    // fall back to typed overload
    cache.get(key, MyType.class, loader);
}

Prevention

When it happens

Trigger: Calling cache.get(key, loader), getAsync, getOrDefault, or getOrNull on a Redis cache whose value type was not configured at build time (no quarkus.cache.redis.<cache>.value-type and no inferable @CacheResult type).

Common situations: Programmatically created/obtained caches (CacheManager.getCache) used with the untyped API; configuration-only caches without any annotated method; tests obtaining caches by name.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/97e3d9583ecc106c. Report an issue: GitHub.