-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
NPE on missing service class #1189
Comments
I think it's something to do with the class originally being present, the service meta-inf file getting generated, the service class source file later being removed from the module, and it being compiled again without being cleaned first. |
Looks like a simple one-line fix. If an .flatMap(value -> value.accept(this, null).stream()) is the string |
Fixes #1189. Closes https://github.com/google/auto/pull/1190/files. Many thanks to @astubbs for the bug report and repro. If an `@AutoService` annotation references a missing class, the `value` on [this line](https://github.com/google/auto/blob/15c76191f79a2a26a9f914541a5c9ac4965dd0c7/service/processor/src/main/java/com/google/auto/service/processor/AutoServiceProcessor.java#L306)... ```java .flatMap(value -> value.accept(this, null).stream()) ``` is the string `"<error>"`, due to quirky javac behaviour. Currently, the visitor expects an array of class literals, or, in its recursive call, a single class literal, but not a string. Since the visitor has no override for [`visitString`](https://docs.oracle.com/en/java/javase/11/docs/api/java.compiler/javax/lang/model/element/AnnotationValueVisitor.html#visitString(java.lang.String,P)), a null default value is returned. We can simply provide an empty `ImmutableSet` as the default value to fix the problem. There is no need to handle this error case specially, since the compiler will be outputting its own errors about the missing class anyway. RELNOTES=AutoService no longer throws an exception for a missing service class. PiperOrigin-RevId: 407146682
Fixes #1189. Closes https://github.com/google/auto/pull/1190/files. Many thanks to @astubbs for the bug report and repro, which was the basis for the new test here. If an `@AutoService` annotation references a missing class, the `value` on [this line](https://github.com/google/auto/blob/15c76191f79a2a26a9f914541a5c9ac4965dd0c7/service/processor/src/main/java/com/google/auto/service/processor/AutoServiceProcessor.java#L306)... ```java .flatMap(value -> value.accept(this, null).stream()) ``` is the string `"<error>"`, due to quirky javac behaviour. Currently, the visitor expects an array of class literals, or, in its recursive call, a single class literal, but not a string. Since the visitor has no override for [`visitString`](https://docs.oracle.com/en/java/javase/11/docs/api/java.compiler/javax/lang/model/element/AnnotationValueVisitor.html#visitString(java.lang.String,P)), a null default value is returned. We can simply provide an empty `ImmutableSet` as the default value to fix the problem. There is no need to handle this error case specially, since the compiler will be outputting its own errors about the missing class anyway. RELNOTES=AutoService no longer throws an exception for a missing service class. PiperOrigin-RevId: 407146682
I think this is happening to me after changing moving my implementations around
Haven't quite been able to narrow it down exactly yet though..Reproduced in this PR - see failing tests.version: 1.0
The text was updated successfully, but these errors were encountered: