Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛Compile error when using injection within an inner class #138

Open
Luolc opened this issue Nov 23, 2016 · 0 comments
Open

🐛Compile error when using injection within an inner class #138

Luolc opened this issue Nov 23, 2016 · 0 comments

Comments

@Luolc
Copy link

Luolc commented Nov 23, 2016

I wrote a new project to reproduce the bug.

In MainActivity, I simply wrote an inner class ExtraHolder and used @InjectExtra in it.

public class MainActivity extends AppCompatActivity {

    public class ExtraHolder {

        @InjectExtra int extra;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

Then compilation encountered an error with stacktrace as following:

22:20:32.699 [ERROR] [org.gradle.BuildExceptionReporter] 
22:20:32.700 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
22:20:32.700 [ERROR] [org.gradle.BuildExceptionReporter] 
22:20:32.700 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
22:20:32.700 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':app:compileDebugJavaWithJavac'.
22:20:32.700 [ERROR] [org.gradle.BuildExceptionReporter] > Compilation failed; see the compiler error output for details.
22:20:32.700 [ERROR] [org.gradle.BuildExceptionReporter] 
22:20:32.700 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is:
22:20:32.700 [ERROR] [org.gradle.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugJavaWithJavac'.
22:20:32.701 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
22:20:32.703 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
22:20:32.703 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
22:20:32.703 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:66)
22:20:32.703 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
22:20:32.703 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
22:20:32.704 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
22:20:32.704 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
22:20:32.704 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
22:20:32.704 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
22:20:32.704 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
22:20:32.704 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)
22:20:32.704 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
22:20:32.704 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
22:20:32.704 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
22:20:32.704 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details.
22:20:32.705 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:48)
22:20:32.705 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:33)
22:20:32.705 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:104)
22:20:32.705 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:53)
22:20:32.705 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:38)
22:20:32.705 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:35)
22:20:32.705 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25)
22:20:32.705 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.compile.incremental.IncrementalCompilationFinalizer.execute(IncrementalCompilationFinalizer.java:39)
22:20:32.705 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.compile.incremental.IncrementalCompilationFinalizer.execute(IncrementalCompilationFinalizer.java:24)
22:20:32.705 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:163)
22:20:32.705 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:127)
22:20:32.705 [ERROR] [org.gradle.BuildExceptionReporter] 	at com.android.build.gradle.tasks.factory.AndroidJavaCompile.compile(AndroidJavaCompile.java:49)
22:20:32.705 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
22:20:32.705 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:245)
22:20:32.705 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:221)
22:20:32.705 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:232)
22:20:32.705 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:210)
22:20:32.706 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
22:20:32.706 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
22:20:32.706 [ERROR] [org.gradle.BuildExceptionReporter] 	... 14 more
22:20:32.706 [ERROR] [org.gradle.BuildExceptionReporter] 

The generated Henson class is:

public class Henson {
  private Henson() {
  }

  public static WithContextSetState with(Context context) {
    return new com.luolc.darttestsample.Henson.WithContextSetState(context);
  }

  public static class WithContextSetState {
    private Context context;

    private WithContextSetState(Context context) {
      this.context = context;
    }

    public MainActivity.ExtraHolder$$IntentBuilder gotoExtraHolder() {
      return new com.luolc.darttestsample.MainActivity.ExtraHolder$$IntentBuilder(context);
    }
  }
}

In which, MainActivity directed to the origin code.

I also tried static inner class but the error still existed.

The generated IntentBuilder class is:

public class MainActivity$ExtraHolder$$IntentBuilder {
  private Intent intent;

  private Bundler bundler = Bundler.create();

  public MainActivity$ExtraHolder$$IntentBuilder(Context context) {
    intent = new Intent(context, MainActivity$ExtraHolder.class);
  }

  public MainActivity$ExtraHolder$$IntentBuilder.AllSet extra(int extra) {
    bundler.put("extra", extra);
    return new MainActivity$ExtraHolder$$IntentBuilder.AllSet();
  }

  public class AllSet {
    public Intent build() {
      intent.putExtras(bundler.get());
      return intent;
    }
  }
}
Luolc added a commit to Luolc/dart that referenced this issue Nov 23, 2016
Luolc added a commit to Luolc/dart that referenced this issue Jan 4, 2017
Luolc added a commit to Luolc/dart that referenced this issue Jan 4, 2017
Luolc added a commit to Luolc/dart that referenced this issue Jan 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant