{"record":{"id":"2cb151cb532119fd","repo":"greenrobot/EventBus","slug":"could-not-write-source-for-index","errorCode":null,"errorMessage":"Could not write source for ${index}","messagePattern":"Could not write source for (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"EventBusAnnotationProcessor/src/org/greenrobot/eventbus/annotationprocessor/EventBusAnnotationProcessor.java","lineNumber":359,"sourceCode":"            writer.write(\"    static {\\n\");\n            writer.write(\"        SUBSCRIBER_INDEX = new HashMap<Class<?>, SubscriberInfo>();\\n\\n\");\n            writeIndexLines(writer, myPackage);\n            writer.write(\"    }\\n\\n\");\n            writer.write(\"    private static void putIndex(SubscriberInfo info) {\\n\");\n            writer.write(\"        SUBSCRIBER_INDEX.put(info.getSubscriberClass(), info);\\n\");\n            writer.write(\"    }\\n\\n\");\n            writer.write(\"    @Override\\n\");\n            writer.write(\"    public SubscriberInfo getSubscriberInfo(Class<?> subscriberClass) {\\n\");\n            writer.write(\"        SubscriberInfo info = SUBSCRIBER_INDEX.get(subscriberClass);\\n\");\n            writer.write(\"        if (info != null) {\\n\");\n            writer.write(\"            return info;\\n\");\n            writer.write(\"        } else {\\n\");\n            writer.write(\"            return null;\\n\");\n            writer.write(\"        }\\n\");\n            writer.write(\"    }\\n\");\n            writer.write(\"}\\n\");\n        } catch (IOException e) {\n            throw new RuntimeException(\"Could not write source for \" + index, e);\n        } finally {\n            if (writer != null) {\n                try {\n                    writer.close();\n                } catch (IOException e) {\n                    //Silent\n                }\n            }\n        }\n    }\n\n    private void writeIndexLines(BufferedWriter writer, String myPackage) throws IOException {\n        for (TypeElement subscriberTypeElement : methodsByClass.keySet()) {\n            if (classesToSkip.contains(subscriberTypeElement)) {\n                continue;\n            }\n\n            String subscriberClass = getClassString(subscriberTypeElement, myPackage);","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/greenrobot/EventBus/blob/0194926b3bcf70cc0d7bfd3c5da16708dd5ab876/EventBusAnnotationProcessor/src/org/greenrobot/eventbus/annotationprocessor/EventBusAnnotationProcessor.java#L341-L377","documentation":"Thrown as RuntimeException from the EventBusAnnotationProcessor when an IOException occurs while writing the generated Java source of the subscriber index class (the createAnnotatedMethods/write path that emits the class registered via the eventbusIndex compiler argument). The annotation processor streams the index source file with a BufferedWriter; any I/O failure (disk full, file locked, Filer restrictions, IDE annotation-processing cache corruption) aborts the compile with this wrapper.","triggerScenarios":"Compiling with the EventBus annotation processor (org.greenrobot:eventbus-annotation-processor on the annotationProcessor/kapt/apt classpath) and the javac Filer throwing IOException while creating/writing the generated index .java file: read-only or full build directory, antivirus/file locks on Windows, kapt incremental-cache corruption, or two processors claiming the same generated file name.","commonSituations":"Windows machines with antivirus locking generated-sources directories; Gradle incremental/kapt cache corruption after a cancelled build; CI containers with exhausted disk or read-only output mounts; project paths with unusual characters.","solutions":["Clean the build caches and output dirs: ./gradlew clean and delete build/ plus the kapt/annotation-processor cache, then rebuild","Free disk space / fix permissions on the build output directory","On Windows, exclude the project build folders from antivirus scanning","Verify only one annotation processor generates the index and the eventbusIndex apt argument is unique per module (e.g. ${modulePackage}.MyEventBusIndex)"],"exampleFix":"# before: repeated failing build with 'Could not write source for ...'\n./gradlew :app:assembleDebug\n\n# after: purge caches then rebuild\n./gradlew clean --rerun-tasks\nrm -rf app/build ~/.gradle/caches/build-cache-1\n./gradlew :app:assembleDebug","handlingStrategy":"retry","validationCode":"// CI/build hygiene: writable, non-duplicated generated-sources dir\n// build.gradle (Groovy DSL)\n// ensure each module declares a UNIQUE index name to avoid Filer clashes\nandroid {\n    defaultConfig {\n        javaCompileOptions {\n            annotationProcessorOptions {\n                arguments = [ eventbusIndex : project.group.toString() + '.' + project.name + 'EventBusIndex' ]\n            }\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"# Shell-level retry: transient IO locks (Windows AV, CI disk) often clear on retry\nfor i in 1 2 3; do\n    ./gradlew :app:assembleDebug && break\n    [ \"$i\" = \"3\" ] && exit 1\n    ./gradlew clean\n    sleep 5\ndone","preventionTips":["Clean build dirs after cancelled builds or IDE crashes","Give each module a unique eventbusIndex name","Exclude build/ from antivirus scanning on Windows dev machines"],"tags":["eventbus","annotation-processor","build","io","kapt"],"backgroundTag":null,"analyzedSha":"0194926b3bcf70cc0d7bfd3c5da16708dd5ab876","analyzedAt":"2026-08-14T10:41:08.786Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}