Skip to content

Commit dfcdc9c

Browse files
bcorsoDagger Team
authored and
Dagger Team
committed
Remove the ignorePrivateAndStaticInjectionForComponent compiler option.
This option was only used by the TCK tests, so I've replaced the compiler option with a hard-coded check for the TCK package. As was stated in the javadoc for the flag, it was not meant to be used for other purposes, so removing it should be fine. This change also fixes a some memory bugs in how `InjectValidator` was previously implemented. 1. Now, only a single validator instance is used in the common case where `privateMemberDiagnostic`/`staticMemberDiagnostic` have the default value (`ERROR`). Previously, this resulted in at least 3 instances being used, which duplicated caching across all three instances 2. Now, both `validator` and `validatorWhenGeneratingCode` have their caches cleared between rounds. Previously, only `validator` had its cache cleared because `validatorWhenGeneratingCode` was being created and managed outside Dagger. This also created a memory leak in one case because it was used within a scoped binding and it's cache was never cleared. RELNOTES=Remove the `ignorePrivateAndStaticInjectionForComponent` compiler option. PiperOrigin-RevId: 686174065
1 parent fbb7b3c commit dfcdc9c

File tree

6 files changed

+319
-331
lines changed

6 files changed

+319
-331
lines changed

java/dagger/internal/codegen/bindinggraphvalidation/InjectBindingValidator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final class InjectBindingValidator extends ValidationBindingGraphPlugin {
3333

3434
@Inject
3535
InjectBindingValidator(InjectValidator injectValidator) {
36-
this.injectValidator = injectValidator.whenGeneratingCode();
36+
this.injectValidator = injectValidator;
3737
}
3838

3939
@Override
@@ -50,7 +50,8 @@ public void visitGraph(BindingGraph bindingGraph, DiagnosticReporter diagnosticR
5050

5151
private void validateInjectionBinding(Binding node, DiagnosticReporter diagnosticReporter) {
5252
ValidationReport typeReport =
53-
injectValidator.validate(node.key().type().xprocessing().getTypeElement());
53+
injectValidator.validateWhenGeneratingCode(
54+
node.key().type().xprocessing().getTypeElement());
5455
for (Item item : typeReport.allItems()) {
5556
diagnosticReporter.reportBinding(item.kind(), node, item.message());
5657
}

java/dagger/internal/codegen/compileroption/CompilerOptions.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,6 @@ public final boolean doCheckForNulls() {
5454
*/
5555
public abstract boolean includeStacktraceWithDeferredErrorMessages();
5656

57-
/**
58-
* If {@code true}, Dagger will generate factories and components even if some members-injected
59-
* types have {@code private} or {@code static} {@code @Inject}-annotated members.
60-
*
61-
*

This should only ever be enabled by the TCK tests. Disabling this validation could lead to

62-
* generating code that does not compile.
63-
*/
64-
public abstract boolean ignorePrivateAndStaticInjectionForComponent();
65-
6657
public abstract ValidationType scopeCycleValidationType();
6758

6859
/**

java/dagger/internal/codegen/compileroption/ProcessingEnvironmentCompilerOptions.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import static dagger.internal.codegen.compileroption.ProcessingEnvironmentCompilerOptions.Feature.FLOATING_BINDS_METHODS;
3030
import static dagger.internal.codegen.compileroption.ProcessingEnvironmentCompilerOptions.Feature.FORMAT_GENERATED_SOURCE;
3131
import static dagger.internal.codegen.compileroption.ProcessingEnvironmentCompilerOptions.Feature.GENERATED_CLASS_EXTENDS_COMPONENT;
32-
import static dagger.internal.codegen.compileroption.ProcessingEnvironmentCompilerOptions.Feature.IGNORE_PRIVATE_AND_STATIC_INJECTION_FOR_COMPONENT;
3332
import static dagger.internal.codegen.compileroption.ProcessingEnvironmentCompilerOptions.Feature.IGNORE_PROVISION_KEY_WILDCARDS;
3433
import static dagger.internal.codegen.compileroption.ProcessingEnvironmentCompilerOptions.Feature.INCLUDE_STACKTRACE_WITH_DEFERRED_ERROR_MESSAGES;
3534
import static dagger.internal.codegen.compileroption.ProcessingEnvironmentCompilerOptions.Feature.PLUGINS_VISIT_FULL_BINDING_GRAPHS;
@@ -139,11 +138,6 @@ public boolean includeStacktraceWithDeferredErrorMessages() {
139138
return isEnabled(INCLUDE_STACKTRACE_WITH_DEFERRED_ERROR_MESSAGES);
140139
}
141140

142-
@Override
143-
public boolean ignorePrivateAndStaticInjectionForComponent() {
144-
return isEnabled(IGNORE_PRIVATE_AND_STATIC_INJECTION_FOR_COMPONENT);
145-
}
146-
147141
@Override
148142
public ValidationType scopeCycleValidationType() {
149143
return parseOption(DISABLE_INTER_COMPONENT_SCOPE_VALIDATION);
@@ -325,8 +319,6 @@ enum Feature implements EnumOption {
325319

326320
INCLUDE_STACKTRACE_WITH_DEFERRED_ERROR_MESSAGES,
327321

328-
IGNORE_PRIVATE_AND_STATIC_INJECTION_FOR_COMPONENT,
329-
330322
EXPERIMENTAL_AHEAD_OF_TIME_SUBCOMPONENTS,
331323

332324
FORCE_USE_SERIALIZED_COMPONENT_IMPLEMENTATIONS,

java/dagger/internal/codegen/javac/JavacPluginCompilerOptions.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ public boolean includeStacktraceWithDeferredErrorMessages() {
6666
return false;
6767
}
6868

69-
@Override
70-
public boolean ignorePrivateAndStaticInjectionForComponent() {
71-
return false;
72-
}
73-
7469
@Override
7570
public ValidationType scopeCycleValidationType() {
7671
return NONE;

java/dagger/internal/codegen/validation/InjectBindingRegistryImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ final class InjectBindingRegistryImpl implements InjectBindingRegistry {
8484
private final XProcessingEnv processingEnv;
8585
private final XMessager messager;
8686
private final InjectValidator injectValidator;
87-
private final InjectValidator injectValidatorWhenGeneratingCode;
8887
private final KeyFactory keyFactory;
8988
private final BindingFactory bindingFactory;
9089
private final CompilerOptions compilerOptions;
@@ -106,7 +105,7 @@ void generateBindings(SourceFileGenerator generator) throws SourceFileGenerat
106105
checkState(!binding.unresolved().isPresent());
107106
XType type = binding.key().type().xprocessing();
108107
if (!isDeclared(type)
109-
|| injectValidatorWhenGeneratingCode.validate(type.getTypeElement()).isClean()) {
108+
|| injectValidator.validateWhenGeneratingCode(type.getTypeElement()).isClean()) {
110109
generator.generate(binding);
111110
}
112111
materializedBindingKeys.add(binding.key());
@@ -223,7 +222,6 @@ private void tryToCacheBinding(B binding) {
223222
this.processingEnv = processingEnv;
224223
this.messager = messager;
225224
this.injectValidator = injectValidator;
226-
this.injectValidatorWhenGeneratingCode = injectValidator.whenGeneratingCode();
227225
this.keyFactory = keyFactory;
228226
this.bindingFactory = bindingFactory;
229227
this.compilerOptions = compilerOptions;

0 commit comments

Comments
 (0)