diff --git a/EventBusAnnotationProcessor/src/org/greenrobot/eventbus/annotationprocessor/EventBusAnnotationProcessor.java b/EventBusAnnotationProcessor/src/org/greenrobot/eventbus/annotationprocessor/EventBusAnnotationProcessor.java index c37c18a5..b82401ab 100644 --- a/EventBusAnnotationProcessor/src/org/greenrobot/eventbus/annotationprocessor/EventBusAnnotationProcessor.java +++ b/EventBusAnnotationProcessor/src/org/greenrobot/eventbus/annotationprocessor/EventBusAnnotationProcessor.java @@ -318,6 +318,14 @@ private void createInfoIndexFile(String index) { if (myPackage != null) { writer.write("package " + myPackage + ";\n\n"); } + + int indexSize = methodsByClass.size() - classesToSkip.size(); + + // sanity check + if (indexSize < 0) { + indexSize = 0; + } + writer.write("import org.greenrobot.eventbus.meta.SimpleSubscriberInfo;\n"); writer.write("import org.greenrobot.eventbus.meta.SubscriberMethodInfo;\n"); writer.write("import org.greenrobot.eventbus.meta.SubscriberInfo;\n"); @@ -329,7 +337,7 @@ private void createInfoIndexFile(String index) { writer.write("public class " + clazz + " implements SubscriberInfoIndex {\n"); writer.write(" private static final Map, SubscriberInfo> SUBSCRIBER_INDEX;\n\n"); writer.write(" static {\n"); - writer.write(" SUBSCRIBER_INDEX = new HashMap, SubscriberInfo>();\n\n"); + writer.write(" SUBSCRIBER_INDEX = new HashMap, SubscriberInfo>(" + indexSize + ");\n\n"); writeIndexLines(writer, myPackage); writer.write(" }\n\n"); writer.write(" private static void putIndex(SubscriberInfo info) {\n");