diff --git a/gradle/javadoc_cleanup.gradle b/gradle/javadoc_cleanup.gradle
index 12216464a7..64f6437288 100644
--- a/gradle/javadoc_cleanup.gradle
+++ b/gradle/javadoc_cleanup.gradle
@@ -29,6 +29,31 @@ def fixJavadocFile(file) {
// lots of spaces after the @Nullable annotations
fileContents = fileContents.replaceAll("@Nullable\\s{4,}", "@Nullable ");
+ // javadoc bug: duplicates the link to @NonNull for some reason
+ def nonNullText1 = "@NonNull";
+
+ fileContents = fileContents.replace(nonNullText1 + " " + nonNullText1, nonNullText1);
+ fileContents = fileContents.replace(nonNullText1 + "\n " + nonNullText1, nonNullText1);
+ fileContents = fileContents.replace(nonNullText1 + "\r\n " + nonNullText1, nonNullText1);
+
+ def nonNullText2 = "@NonNull";
+ fileContents = fileContents.replace(nonNullText2 + " " + nonNullText2, nonNullText2);
+ fileContents = fileContents.replace(nonNullText2 + "\n " + nonNullText2, nonNullText2);
+ fileContents = fileContents.replace(nonNullText2 + "\r\n " + nonNullText2, nonNullText2);
+
+ // javadoc bug: duplicates the link to @Nullable for some reason
+ def nullableText1 = "@Nullable";
+
+ fileContents = fileContents.replace(nullableText1 + " " + nullableText1, nullableText1);
+ fileContents = fileContents.replace(nullableText1 + "\n " + nullableText1, nullableText1);
+ fileContents = fileContents.replace(nullableText1 + "\r\n " + nullableText1, nullableText1);
+
+ def nullableText2 = "@Nullable";
+
+ fileContents = fileContents.replace(nullableText2 + " " + nullableText2, nullableText2);
+ fileContents = fileContents.replace(nullableText2 + "\n " + nullableText2, nullableText2);
+ fileContents = fileContents.replace(nullableText2 + "\r\n " + nullableText2, nullableText2);
+
file.setText(fileContents, 'UTF-8');
}