greenrobot/EventBus · error · RuntimeException
Could not write source for ${index}
Error message
Could not write source for ${index} What it means
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.
Source
Thrown at EventBusAnnotationProcessor/src/org/greenrobot/eventbus/annotationprocessor/EventBusAnnotationProcessor.java:359
writer.write(" static {\n");
writer.write(" SUBSCRIBER_INDEX = new HashMap<Class<?>, SubscriberInfo>();\n\n");
writeIndexLines(writer, myPackage);
writer.write(" }\n\n");
writer.write(" private static void putIndex(SubscriberInfo info) {\n");
writer.write(" SUBSCRIBER_INDEX.put(info.getSubscriberClass(), info);\n");
writer.write(" }\n\n");
writer.write(" @Override\n");
writer.write(" public SubscriberInfo getSubscriberInfo(Class<?> subscriberClass) {\n");
writer.write(" SubscriberInfo info = SUBSCRIBER_INDEX.get(subscriberClass);\n");
writer.write(" if (info != null) {\n");
writer.write(" return info;\n");
writer.write(" } else {\n");
writer.write(" return null;\n");
writer.write(" }\n");
writer.write(" }\n");
writer.write("}\n");
} catch (IOException e) {
throw new RuntimeException("Could not write source for " + index, e);
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
//Silent
}
}
}
}
private void writeIndexLines(BufferedWriter writer, String myPackage) throws IOException {
for (TypeElement subscriberTypeElement : methodsByClass.keySet()) {
if (classesToSkip.contains(subscriberTypeElement)) {
continue;
}
String subscriberClass = getClassString(subscriberTypeElement, myPackage);View on GitHub (pinned to 0194926b3b)
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)
Example fix
# before: repeated failing build with 'Could not write source for ...' ./gradlew :app:assembleDebug # after: purge caches then rebuild ./gradlew clean --rerun-tasks rm -rf app/build ~/.gradle/caches/build-cache-1 ./gradlew :app:assembleDebug
Defensive patterns
Strategy: retry
Validate before calling
// CI/build hygiene: writable, non-duplicated generated-sources dir
// build.gradle (Groovy DSL)
// ensure each module declares a UNIQUE index name to avoid Filer clashes
android {
defaultConfig {
javaCompileOptions {
annotationProcessorOptions {
arguments = [ eventbusIndex : project.group.toString() + '.' + project.name + 'EventBusIndex' ]
}
}
}
} Try / catch
# Shell-level retry: transient IO locks (Windows AV, CI disk) often clear on retry
for i in 1 2 3; do
./gradlew :app:assembleDebug && break
[ "$i" = "3" ] && exit 1
./gradlew clean
sleep 5
done Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not inspect methods of ${clazz.getName()}. Please make
- It looks like you are using EventBus on Android, make sure t
- Subscriber ${subscriber.getClass()} already registered to ev
- This method may only be called from inside event handling me
- Event may not be null
AI-assisted analysis of greenrobot/EventBus@0194926b3b (2026-08-14).
Data as JSON: /api/errors/2cb151cb532119fd.
Report an issue: GitHub.