Skip to content

Commit 613a074

Browse files
authored
cleanup(generator): remove javax.annotation.Nonnull usage (#13960)
This PR removes all occurrences of `javax.annotation.Nonnull` (both imports and annotations) from the codebase of `gapic-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 legacy `javax.annotation.Nonnull` annotations are redundant and can be safely removed. ### Changes: - Removed `import javax.annotation.Nonnull;` and `@Nonnull` from 4 files in the generator codebase (`TypeParser.java`, `SourceCodeInfoLocation.java`, `TryCatchStatement.java`, and `ImportWriterVisitor.java`). - Formatted the modified files using `fmt-maven-plugin`. - Verified that all compilation references to `javax.annotation.Nonnull` under `gapic-generator-java` have been eliminated.
1 parent f84034b commit 613a074

5 files changed

Lines changed: 11 additions & 19 deletions

File tree

sdk-platform-java/gapic-generator-java/pom.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,7 @@
398398
<version>${junit.version}</version>
399399
<scope>test</scope>
400400
</dependency>
401-
<dependency>
402-
<groupId>com.google.code.findbugs</groupId>
403-
<artifactId>jsr305</artifactId>
404-
<version>3.0.2</version>
405-
</dependency>
401+
406402
<dependency>
407403
<groupId>com.google.api</groupId>
408404
<artifactId>api-common</artifactId>

sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/engine/ast/TryCatchStatement.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.ArrayList;
2121
import java.util.Collections;
2222
import java.util.List;
23-
import javax.annotation.Nonnull;
2423
import org.jspecify.annotations.NullMarked;
2524
import org.jspecify.annotations.Nullable;
2625

@@ -62,7 +61,7 @@ public abstract static class Builder {
6261

6362
public abstract Builder setIsSampleCode(boolean isSampleCode);
6463

65-
public Builder addCatch(@Nonnull VariableExpr variableExpr, List<Statement> body) {
64+
public Builder addCatch(VariableExpr variableExpr, List<Statement> body) {
6665
List<VariableExpr> catchVarExprs = new ArrayList<>(catchVariableExprs());
6766
catchVarExprs.add(variableExpr);
6867
setCatchVariableExprs(catchVarExprs);

sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/engine/writer/ImportWriterVisitor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
import java.util.Set;
7070
import java.util.TreeSet;
7171
import java.util.stream.Collectors;
72-
import javax.annotation.Nonnull;
7372
import org.jspecify.annotations.NullMarked;
7473
import org.jspecify.annotations.Nullable;
7574

@@ -93,12 +92,12 @@ public void clear() {
9392
importShortNames.clear();
9493
}
9594

96-
public void initialize(@Nonnull String currentPackage) {
95+
public void initialize(String currentPackage) {
9796
this.currentPackage = currentPackage;
9897
currentClassName = null;
9998
}
10099

101-
public void initialize(@Nonnull String currentPackage, @Nonnull String currentClassName) {
100+
public void initialize(String currentPackage, String currentClassName) {
102101
this.currentPackage = currentPackage;
103102
this.currentClassName = currentClassName;
104103
}

sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/SourceCodeInfoLocation.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package com.google.api.generator.gapic.model;
1616

1717
import com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location;
18-
import javax.annotation.Nonnull;
1918
import org.jspecify.annotations.NullMarked;
2019

2120
/**
@@ -24,13 +23,13 @@
2423
*/
2524
@NullMarked
2625
public class SourceCodeInfoLocation {
27-
@Nonnull private final Location location;
26+
private final Location location;
2827

2928
private SourceCodeInfoLocation(Location location) {
3029
this.location = location;
3130
}
3231

33-
public static SourceCodeInfoLocation create(@Nonnull Location location) {
32+
public static SourceCodeInfoLocation create(Location location) {
3433
return new SourceCodeInfoLocation(location);
3534
}
3635

sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/TypeParser.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.util.Arrays;
3535
import java.util.List;
3636
import java.util.Map;
37-
import javax.annotation.Nonnull;
3837
import org.jspecify.annotations.NullMarked;
3938

4039
@NullMarked
@@ -64,7 +63,7 @@ public class TypeParser {
6463
.put(JavaType.BYTE_STRING, REFERENCE_BYTE_STRING)
6564
.build();
6665

67-
public static TypeNode parseType(@Nonnull FieldDescriptor field) {
66+
public static TypeNode parseType(FieldDescriptor field) {
6867
if (field.isMapField()) {
6968
return createMapType(field);
7069
}
@@ -85,11 +84,11 @@ public static TypeNode parseType(@Nonnull FieldDescriptor field) {
8584
return TypeNode.withReference(parseFieldReference(field));
8685
}
8786

88-
public static TypeNode parseType(@Nonnull Descriptor messageDescriptor) {
87+
public static TypeNode parseType(Descriptor messageDescriptor) {
8988
return TypeNode.withReference(parseMessageReference(messageDescriptor));
9089
}
9190

92-
public static TypeNode parseType(@Nonnull EnumDescriptor enumDescriptor) {
91+
public static TypeNode parseType(EnumDescriptor enumDescriptor) {
9392
return TypeNode.withReference(parseEnumReference(enumDescriptor));
9493
}
9594

@@ -121,7 +120,7 @@ static Reference parseFieldReference(FieldDescriptor field) {
121120
}
122121

123122
@VisibleForTesting
124-
static Reference parseMessageReference(@Nonnull Descriptor messageDescriptor) {
123+
static Reference parseMessageReference(Descriptor messageDescriptor) {
125124
List<String> outerNestedTypeNames = new ArrayList<>();
126125
FileOptions fileOptions = messageDescriptor.getFile().getOptions();
127126
String javaOuterClassname =
@@ -181,7 +180,7 @@ static Reference parseMessageReference(@Nonnull Descriptor messageDescriptor) {
181180
}
182181

183182
@VisibleForTesting
184-
static Reference parseEnumReference(@Nonnull EnumDescriptor enumDescriptor) {
183+
static Reference parseEnumReference(EnumDescriptor enumDescriptor) {
185184
// This is similar to parseMessageReference, but we make it a separate method because
186185
// EnumDescriptor and Descriptor are sibling types.
187186
FileOptions fileOptions = enumDescriptor.getFile().getOptions();

0 commit comments

Comments
 (0)