Invalid code generated when annotating private fields with @Inject #113

Closed
gunnarmorling opened this Issue Nov 17, 2012 · 3 comments

Projects

None yet

3 participants

@gunnarmorling

When annotating a private field with visibility with @Inject, the annotation processor still generates code which directly accesses that field and thus can't be compiled. I think the annotation processor should better create an error clearly indicating the issue. On the other hand injecting private field works when using the reflective plug-in, so maybe the processor could also generate code which accesses the field reflectively in such cases.

@swankjesse
Contributor

We should just report an error in either case. We don't want to rely on reflection.

@gunnarmorling

Or maybe invoke a setter method (if there is one)?

@swankjesse
Contributor

If application code wants private or final, it should use constructor injection.

@JakeWharton JakeWharton added a commit that referenced this issue Mar 26, 2013
@JakeWharton JakeWharton Forbid injection on private fields.
Closes #181. Closes #113.
9a3102d
@JakeWharton JakeWharton added a commit that referenced this issue Mar 26, 2013
@JakeWharton JakeWharton Forbid injection on private fields.
Closes #181. Closes #113.
b3b0747
@JakeWharton JakeWharton added a commit that referenced this issue Mar 26, 2013
@JakeWharton JakeWharton Forbid injection on private fields.
Closes #181. Closes #113.
23f079f
@JakeWharton JakeWharton added a commit that referenced this issue Mar 27, 2013
@JakeWharton JakeWharton Add restrictions around injectable targets.
 * Private fields are not supported.
 * Private constructors are not supported.
 * Methods are not supported.

Closes #181. Closes #113. Closes #112.
e332b64
@JakeWharton JakeWharton added a commit that closed this issue Mar 27, 2013
@JakeWharton JakeWharton Add restrictions around injectable targets.
 * Private fields are not supported.
 * Private constructors are not supported.
 * Methods are not supported.

Closes #181. Closes #113. Closes #112.
b619788
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment