Skip to content

Commit

Permalink
Do not allow calls to earlySingletonComponent() if there are no @Earl…
Browse files Browse the repository at this point in the history
…yEntryPoints.

Before this change, this method would not throw if shareTestComponent was enabled, regardless of whether there were any @EarlyEntryPoints. After this change, EarlySingletonComponentCreatorImpl is no longer generated unless there are aggregated @EarlyEntryPoints. The ability to reflect on this class is what determines whether an exception is thrown.

RELNOTES=EarlyEntryPoints#get() will now throw if there are no @EarlyEntryPoint annotated interfaces.
PiperOrigin-RevId: 403191264
  • Loading branch information
groakley authored and Dagger Team committed Oct 14, 2021
1 parent 18248ac commit b5ef01c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ private void processComponentTreeDeps(ComponentTreeDepsMetadata metadata) throws

generateComponents(metadata, rootMetadata, componentNames);

// Generate a creator for the early entry point if there is a default component available.
if (isDefaultRoot) {
// Generate a creator for the early entry point if there is a default component available
// and there are early entry points.
if (isDefaultRoot && !metadata.aggregatedEarlyEntryPointDeps().isEmpty()) {
EarlySingletonComponentCreatorGenerator.generate(getProcessingEnv());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ComponentTreeDepsIrCreator private constructor(
return mutableSetOf<ComponentTreeDepsIr>().apply {
aggregatedDepsByRoot.keys.forEach { root ->
val isDefaultRoot = root == DEFAULT_ROOT_CLASS_NAME
val isEarlyEntryPointRoot = isDefaultRoot && rootsUsingSharedComponent.isEmpty()
val isEarlyEntryPointRoot = isDefaultRoot && aggregatedEarlyEntryPointDeps.isNotEmpty()
// We want to base the generated name on the user written root rather than a generated root.
val rootName = if (isDefaultRoot) {
DEFAULT_ROOT_CLASS_NAME
Expand Down
1 change: 0 additions & 1 deletion javatests/dagger/hilt/android/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ android_local_test(
name = "EarlyEntryPointNoEntryPointsDefinedTest",
size = "small",
srcs = ["EarlyEntryPointNoEntryPointsDefinedTest.java"],
javacopts = ["-Adagger.hilt.shareTestComponents=false"], # TODO(b/200821875): Remove explicit flag
manifest_values = {
"minSdkVersion": "14",
},
Expand Down

0 comments on commit b5ef01c

Please sign in to comment.