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

Ability to treat reflection warnings as errors #381

Open
TWiStErRob opened this issue Mar 8, 2020 · 5 comments
Open

Ability to treat reflection warnings as errors #381

TWiStErRob opened this issue Mar 8, 2020 · 5 comments

Comments

@TWiStErRob
Copy link

Given the following class:

@Parcel
data class Parceled @ParcelConstructor constructor(
	val privateField: String
)

I get this build output:

> Task :kaptDebugKotlin
fail-on-warning\build\tmp\kapt3\stubs\debug\com\example\Parceled.java:9: warning: Parceler: Reflection is required to access private field: String privateField, consider using non-private.
    private final java.lang.String privateField = null;

I'm looking for a way to make this warning an error, similar to how lint and javac and kotlinc allows me to.

TWiStErRob added a commit to TWiStErRob/repros that referenced this issue Mar 8, 2020
@TWiStErRob
Copy link
Author

I found a workaround: https://github.com/TWiStErRob/repros/tree/master/parceler/fail-on-warning, but it's quite elaborate.

@johncarl81
Copy link
Owner

I like this idea. We could just change this decorator out for one that validates to an error based on an annotation processor configuration in this location: https://github.com/johncarl81/parceler/blob/master/parceler/src/main/java/org/parceler/internal/ParcelerInvocationBuilderStrategy.java#L40

@johncarl81
Copy link
Owner

Or use a validator that validates a warning to an error.

@TWiStErRob
Copy link
Author

Something like dagger.moduleBindingValidation would be nice.

@TWiStErRob
Copy link
Author

TWiStErRob commented Mar 8, 2020

Hmm, that actually gave me an idea for another workaround:

kapt {
   javacOptions {
      option("-Werror")
   }
}

since these warnings are coming from Javac running the annotation processor on kapt stubs.

Finer control is still appreciated though. 🤓
It is possible that there are multiple annotation processors in one kapt run, and someone would want Parceler to error, but another one has to have the warning (e.g. one a project I work on DBFlow warns, and it can't be fixed); meaning -Werror doesn't work here.

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

2 participants