{"record":{"id":"0c43c6c66539445d","repo":"quarkusio/quarkus","slug":"companions-are-not-supported-in-java-0c43c6","errorCode":null,"errorMessage":"Companions are not supported in Java.","messagePattern":"Companions are not supported in Java\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"extensions/panache/panache-common/deployment/src/main/java/io/quarkus/panache/common/deployment/TypeBundle.java","lineNumber":9,"sourceCode":"package io.quarkus.panache.common.deployment;\n\npublic interface TypeBundle {\n    ByteCodeType entity();\n\n    ByteCodeType entityBase();\n\n    default ByteCodeType entityCompanion() {\n        throw new UnsupportedOperationException(\"Companions are not supported in Java.\");\n    }\n\n    default ByteCodeType entityCompanionBase() {\n        throw new UnsupportedOperationException(\"Companions are not supported in Java.\");\n    }\n\n    ByteCodeType operations();\n\n    ByteCodeType queryType();\n\n    ByteCodeType repository();\n\n    ByteCodeType repositoryBase();\n\n    default ByteCodeType updateType() {\n        throw new UnsupportedOperationException(\"Update types are only supported in MongoDB contexts\");\n    };\n}","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/panache/panache-common/deployment/src/main/java/io/quarkus/panache/common/deployment/TypeBundle.java#L1-L27","documentation":"TypeBundle models the Kotlin companion-class concept used by some Panache bytecode generation (Kotlin builds have entity companions). In pure Java builds companions do not exist, so the default entityCompanion() method throws UnsupportedOperationException if invoked.","triggerScenarios":"A bytecode-generation routine that unconditionally calls bundle.entityCompanion() running against a Java TypeBundle implementation that did not override the default, e.g. during Panache enhancement when processing companions.","commonSituations":"Mixing Java and Kotlin Panache code in one project so the Kotlin-oriented build path runs over Java classes; writing custom TypeBundle implementations for tooling.","solutions":["Do not invoke entityCompanion() for Java entities; guard callers with a Kotlin check before calling.","Override entityCompanion() in a custom TypeBundle only for Kotlin compilations.","Keep Java and Kotlin Panache enhancement paths separate (per-language processing)."],"exampleFix":"// before\nByteCodeType companion = bundle.entityCompanion(); // throws for Java\n// after\nif (isKotlinClass(classInfo)) {\n    ByteCodeType companion = bundle.entityCompanion();\n}\n","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"boolean hasCompanions(ClassInfo ci) {\n    return ci.name().toString().endsWith(\"Kt\") || isKotlinClass(ci);\n}\nif (hasCompanions(classInfo)) bundle.entityCompanion();","tryCatchPattern":"try {\n    bundle.entityCompanion();\n} catch (UnsupportedOperationException e) {\n    // Java entity: skip companion processing\n}","preventionTips":["Only call companion accessors when processing Kotlin classes.","Keep Java and Kotlin enhancement paths separated.","Document custom TypeBundle overrides."],"tags":["panache","build-time","bytecode","kotlin"],"backgroundTag":"unsupported-companion-class","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}