Add @SuppressWarnings to generated classes to fix @Deprecated components#274
Conversation
|
Hi @Randgalt , Is there any chance it gets merged and released? Would you like me to change anything in the PR? |
|
I apologize - I've been slammed at work. I'll look at this in the next day or so. |
One thing for certain, this should be optional behavior. You should add an option to do this. |
|
I'd like to ask a few questions:
|
|
I see it one place, it was added by another dev and I don't remember the details tbh. My initial reaction is to ask why this is necessary? I know that Maven ignores the annotations directory. Doesn't Gradle too? What build system causes the problem. Can you describe how I can see the problem locally? |
|
It's not about Maven or Gradle. It's about javac. Basically, a builder generated for this record can't be compiled with @RecordBuilder
public record DeprecatedComponentRecord(
@Deprecated String oldField, // <-- this `@Deprecated` field is used in the generated builder and this cause compilation issues
String newField
) implements DeprecatedComponentRecordBuilder.With {
}Don't remember if I could suggest to suppress |
|
I did a test where I build |
|
Are you saying javac reports an error when compiles records with deprecated components? Yes, that can happen. But it can be easily suppressed. |
Yes. So, whatever you do to suppress the non-Record-Builder case can be done for the Record-Builder case. |
Not exactly. The record is written by me. I can add |
RecordBuilder copies down any annotations you write/add. If it's not doing it for a particular case we can fix that. |
|
For example, if I add |
|
It didn't help. I still see these warnings: The project is proprietary, so I can't copy-paste the error message fully. It looks like javac reports that it doesn't make sense to deprecate a parameter. Our environment:
The error messages above are clearly not from Error Prone. |
|
@semyon-levin-workato and @remal Here's my proposed solution: #276 - please test with your use case and let me know how it works |
|
I tried you PR and, unfortunately, it doesn't help. I get these errors with it:
import io.soabase.recordbuilder.core.RecordBuilder;
@RecordBuilder
public record TestRecord(
@SuppressWarnings("all") @Deprecated String oldValue
) {
} |
|
@semyon-levin-workato put the |
|
Seems you solution works. However, there are some moments to discuss. I'm adding some review comments to your PR. |
|
Closed this PR because it's not relevant anymore. |
When a record component is annotated with
@Deprecated, the generated builder code references deprecated accessors, causing compilation warnings (or errors with-Werror). This adds@SuppressWarnings({"all", "cast"})at the class level on all generated classes, interfaces, and records.Fixes #273.