cleanup(generator): remove javax.annotation.Nonnull usage - #13960
cleanup(generator): remove javax.annotation.Nonnull usage#13960nnicolee wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request removes redundant @Nonnull annotations and their corresponding imports across several files, including TryCatchStatement.java, ImportWriterVisitor.java, SourceCodeInfoLocation.java, and TypeParser.java, as these classes are already annotated with @NullMarked. Feedback on the changes highlights that the body parameter in the addCatch method of TryCatchStatement.java is currently unused and suggests updating the builder to properly record the catch block statements.
| public Builder addCatch(VariableExpr variableExpr, List<Statement> body) { | ||
| List<VariableExpr> catchVarExprs = new ArrayList<>(catchVariableExprs()); | ||
| catchVarExprs.add(variableExpr); | ||
| setCatchVariableExprs(catchVarExprs); |
There was a problem hiding this comment.
The body parameter in addCatch is currently unused, which means the catch block's statements are ignored and not added to the TryCatchStatement. If TryCatchStatement uses catchBlocks() to store the catch block bodies, you should update this method to also add the body to catchBlocks().
| public Builder addCatch(VariableExpr variableExpr, List<Statement> body) { | |
| List<VariableExpr> catchVarExprs = new ArrayList<>(catchVariableExprs()); | |
| catchVarExprs.add(variableExpr); | |
| setCatchVariableExprs(catchVarExprs); | |
| public Builder addCatch(VariableExpr variableExpr, List<Statement> body) { | |
| List<VariableExpr> catchVarExprs = new ArrayList<>(catchVariableExprs()); | |
| catchVarExprs.add(variableExpr); | |
| setCatchVariableExprs(catchVarExprs); | |
| List<List<Statement>> catchBodies = new ArrayList<>(catchBlocks()); | |
| catchBodies.add(body); | |
| setCatchBlocks(catchBodies); | |
| } |
|
|



This PR removes all occurrences of
javax.annotation.Nonnull(both imports and annotations) from the codebase ofgapic-generator-java.Why this change is needed:
As part of the migration to JSpecify annotations, generator classes are annotated with
@NullMarked, making all unannotated types non-nullable by default. The legacyjavax.annotation.Nonnullannotations are redundant and can be safely removed.Changes:
import javax.annotation.Nonnull;and@Nonnullfrom 4 files in the generator codebase (TypeParser.java,SourceCodeInfoLocation.java,TryCatchStatement.java, andImportWriterVisitor.java).fmt-maven-plugin.javax.annotation.Nonnullundergapic-generator-javahave been eliminated.