quarkusio/quarkus · error · UnsupportedOperationException

Companions are not supported in Java.

Error message

Companions are not supported in Java.

What it means

Kotlin companion-object based Panache is only meaningful for Kotlin MongoDB Panache entities. The Java reactive MongoDB type bundle overrides entityCompanion to fail fast, since Java has no companion objects.

Source

Thrown at extensions/panache/mongodb-panache/deployment/src/main/java/io/quarkus/mongodb/panache/deployment/ReactiveTypeBundle.java:26

import io.quarkus.mongodb.panache.reactive.ReactivePanacheQuery;
import io.quarkus.mongodb.panache.reactive.runtime.JavaReactiveMongoOperations;
import io.quarkus.panache.common.deployment.ByteCodeType;
import io.quarkus.panache.common.deployment.TypeBundle;

public class ReactiveTypeBundle implements TypeBundle {
    @Override
    public ByteCodeType entity() {
        return new ByteCodeType(ReactivePanacheMongoEntity.class);
    }

    @Override
    public ByteCodeType entityBase() {
        return new ByteCodeType(ReactivePanacheMongoEntityBase.class);
    }

    @Override
    public ByteCodeType entityCompanion() {
        throw new UnsupportedOperationException("Companions are not supported in Java.");
    }

    @Override
    public ByteCodeType entityCompanionBase() {
        throw new UnsupportedOperationException("Companions are not supported in Java.");
    }

    @Override
    public ByteCodeType operations() {
        return new ByteCodeType(JavaReactiveMongoOperations.class);
    }

    @Override
    public ByteCodeType queryType() {
        return new ByteCodeType(ReactivePanacheQuery.class);
    }

    @Override

View on GitHub (pinned to e1c734241f)

Solutions

  1. Use the Kotlin type bundle only for Kotlin projects; Java projects should not need companions
  2. If you hit this in a Java app, report it — companion generation should not be requested for Java entities
  3. For Kotlin, use the Kotlin entity base classes/companion support
Defensive patterns

Strategy: type-guard

Validate before calling

if (isKotlinEntity(entityClass)) useKotlinBundle();

Type guard

boolean isKotlinEntity(Class<?> c) {
    return c.isAnnotationPresent(kotlin.Metadata.class);
}

Try / catch

try { bundle.entityCompanion(); } catch (UnsupportedOperationException e) { // Java bundle: switch to Kotlin bundle for Kotlin entities }

Prevention

When it happens

Trigger: Internal/extension code invokes entityCompanion() on the Java ReactiveTypeBundle for reactive MongoDB Panache during bytecode generation.

Common situations: Misconfiguration mixing Kotlin Panache generator expectations with Java modules; upstream bug selecting the wrong TypeBundle; users writing custom build steps calling bundle.entityCompanion().

Related errors


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