{"record":{"id":"dc9ee7285a6b0838","repo":"apache/dubbo","slug":"non-public-interfaces-class-from-different-package","errorCode":null,"errorMessage":"non-public interfaces class from different packages","messagePattern":"non-public interfaces class from different packages","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Mixin.java","lineNumber":98,"sourceCode":"    public static Mixin mixin(Class<?>[] ics, Class<?>[] dcs, ClassLoader cl) {\n        assertInterfaceArray(ics);\n\n        long id = MIXIN_CLASS_COUNTER.getAndIncrement();\n        String pkg = null;\n        ClassGenerator ccp = null, ccm = null;\n        try {\n            ccp = ClassGenerator.newInstance(cl);\n\n            // impl constructor\n            StringBuilder code = new StringBuilder();\n            for (int i = 0; i < dcs.length; i++) {\n                if (!Modifier.isPublic(dcs[i].getModifiers())) {\n                    String npkg = dcs[i].getPackage().getName();\n                    if (pkg == null) {\n                        pkg = npkg;\n                    } else {\n                        if (!pkg.equals(npkg)) {\n                            throw new IllegalArgumentException(\"non-public interfaces class from different packages\");\n                        }\n                    }\n                }\n\n                ccp.addField(\"private \" + dcs[i].getName() + \" d\" + i + \";\");\n\n                code.append('d')\n                        .append(i)\n                        .append(\" = (\")\n                        .append(dcs[i].getName())\n                        .append(\")$1[\")\n                        .append(i)\n                        .append(\"];\\n\");\n                if (MixinAware.class.isAssignableFrom(dcs[i])) {\n                    code.append('d').append(i).append(\".setMixinInstance(this);\\n\");\n                }\n            }\n            ccp.addConstructor(Modifier.PUBLIC, new Class<?>[] {Object[].class}, code.toString());","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Mixin.java#L80-L116","documentation":"Thrown by Mixin.mixin when two or more DELEGATE classes (the dcs array) are non-public AND come from different Java packages. Dubbo generates a single mixin class in one package; non-public types from other packages cannot be referenced there, so the JVM would reject the bytecode. The guard fails fast with IllegalArgumentException.","triggerScenarios":"Mixin.mixin(ics, dcs) where dcs contains package-private delegate classes whose packages differ from each other (or from the first non-public delegate).","commonSituations":"Passing internal/package-private implementation classes from multiple modules as delegates; mixing delegates from library A (package a.b) and library B (package c.d), both non-public.","solutions":["Make the delegate classes public so the generated mixin can reference them from any package.","Restrict all non-public delegates to the same single package.","Wrap the non-public delegates behind a public facade before passing them to Mixin."],"exampleFix":"// before\npackage a.b;\nclass DelegateA {} // package-private\npackage c.d;\nclass DelegateB {} // package-private\nMixin.mixin(ics, new Class[]{ DelegateA.class, DelegateB.class });\n\n// after\npackage a.b;\npublic class DelegateA {} // make public (or keep all delegates in one package)","handlingStrategy":"validation","validationCode":"for (Class<?> dc : dcs) {\n    if (!Modifier.isPublic(dc.getModifiers())) {\n        // ensure all non-public delegates share one package\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer public delegate classes when using Mixin.","If delegates must be package-private, keep them all in the same package.","Validate delegate visibility before calling Mixin.mixin."],"tags":["bytecode","mixin","visibility","validation"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}