Fix error prone warns (#2319)

* Adds a javadoc summary to the methods in the `SerializedName` annotation

Fixes the `MissingSummary` warn given by ErrorProne

* Adds a javadoc summary to the methods of the `ExclusionStrategy` annotation

 Fixes the `MissingSummary` warn given by ErrorProne

* Adds a javadoc summary to `getDeclaringClass()` and `getName()` methods of the `FieldAttributes` class

 Fixes the `MissingSummary` warn given by ErrorProne

* Adds a javadoc summary to `getMajorJavaVersion()` and `isJava9OrLater()` methods of the `JavaVersion` class

 Fixes the `MissingSummary` warn given by ErrorProne

* Adds a comment in the empty catch block of the `AccessChecker:101` class

 Fixes the `EmptyCatch` warn given by ErrorProne

* Adds a comment in the empty catch block of the `DefaultDateTypeAdapter:158` class

 Fixes the `EmptyCatch` warn given by ErrorProne

* Adds a comment in the empty catch blocks of the `UnsafeAllocator:(67|92|113)` class

 Fixes the `EmptyCatch` warn given by ErrorProne

* Adds a comment in the empty catch block of the `DateTypeAdapter:85` class

 Fixes the `EmptyCatch` warn given by ErrorProne

* Fixes javadoc param of the `deserialize(...)` method of the `JsonDeserializer` interface

 Fixes the `InvalidParam` warn given by ErrorProne

* Adds a charset `StandardCharsets.UTF_8` in the `resourceToString()` method of the `ParseBenchmark` class

Fixes the `DefaultCharset` warn given by ErrorProne

* Fixes a typo

* Implements review feedback

* Adds blank line before @ tag.
This commit is contained in:
Maicol 2023-02-17 18:58:16 +01:00 committed by GitHub
parent 779754e0f9
commit 742fd50ff7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 29 additions and 4 deletions

View File

@ -93,12 +93,16 @@ package com.google.gson;
public interface ExclusionStrategy {
/**
* Decides if a field should be skipped during serialization or deserialization.
*
* @param f the field object that is under test
* @return true if the field should be ignored; otherwise false
*/
public boolean shouldSkipField(FieldAttributes f);
/**
* Decides if a class should be serialized or deserialized
*
* @param clazz the class object that is under test
* @return true if the class should be ignored; otherwise false
*/

View File

@ -46,6 +46,8 @@ public final class FieldAttributes {
}
/**
* Gets the declaring Class that contains this field
*
* @return the declaring class that contains this field
*/
public Class<?> getDeclaringClass() {
@ -53,6 +55,8 @@ public final class FieldAttributes {
}
/**
* Gets the name of the field
*
* @return the name of the field
*/
public String getName() {

View File

@ -89,7 +89,7 @@ public interface JsonDeserializer<T> {
* @param json The Json data being deserialized
* @param typeOfT The type of the Object to deserialize to
* @return a deserialized object of the specified type typeOfT which is a subclass of {@code T}
* @throws JsonParseException if json is not in the expected format of {@code typeofT}
* @throws JsonParseException if json is not in the expected format of {@code typeOfT}
*/
public T deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException;

View File

@ -83,10 +83,14 @@ import java.lang.annotation.Target;
public @interface SerializedName {
/**
* The desired name of the field when it is serialized or deserialized.
*
* @return the desired name of the field when it is serialized or deserialized
*/
String value();
/**
* The alternative names of the field when it is deserialized
*
* @return the alternative names of the field when it is deserialized
*/
String[] alternate() default {};

View File

@ -75,6 +75,8 @@ public final class JavaVersion {
}
/**
* Gets the major Java version
*
* @return the major Java version, i.e. '8' for Java 1.8, '9' for Java 9 etc.
*/
public static int getMajorJavaVersion() {
@ -82,6 +84,8 @@ public final class JavaVersion {
}
/**
* Gets a boolean value depending if the application is running on Java 9 or later
*
* @return {@code true} if the application is running on Java 9 or later; and {@code false} otherwise.
*/
public static boolean isJava9OrLater() {

View File

@ -98,6 +98,7 @@ public class ReflectionAccessFilterHelper {
}
};
} catch (NoSuchMethodException ignored) {
// OK: will assume everything is accessible
}
}

View File

@ -64,6 +64,7 @@ public abstract class UnsafeAllocator {
}
};
} catch (Exception ignored) {
// OK: try the next way
}
// try dalvikvm, post-gingerbread
@ -88,6 +89,7 @@ public abstract class UnsafeAllocator {
}
};
} catch (Exception ignored) {
// OK: try the next way
}
// try dalvikvm, pre-gingerbread
@ -108,6 +110,7 @@ public abstract class UnsafeAllocator {
}
};
} catch (Exception ignored) {
// OK: try the next way
}
// give up

View File

@ -81,7 +81,9 @@ public final class DateTypeAdapter extends TypeAdapter<Date> {
for (DateFormat dateFormat : dateFormats) {
try {
return dateFormat.parse(s);
} catch (ParseException ignored) {}
} catch (ParseException ignored) {
// OK: try the next format
}
}
}
try {

View File

@ -154,7 +154,9 @@ public final class DefaultDateTypeAdapter<T extends Date> extends TypeAdapter<T>
for (DateFormat dateFormat : dateFormats) {
try {
return dateFormat.parse(s);
} catch (ParseException ignored) {}
} catch (ParseException ignored) {
// OK: try the next format
}
}
}

View File

@ -40,6 +40,7 @@ import java.io.Reader;
import java.io.StringWriter;
import java.lang.reflect.Type;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@ -137,7 +138,7 @@ public final class ParseBenchmark {
ZipFile zipFile = new ZipFile(getResourceFile("/ParseBenchmarkData.zip"));
try {
ZipEntry zipEntry = zipFile.getEntry(fileName);
Reader reader = new InputStreamReader(zipFile.getInputStream(zipEntry));
Reader reader = new InputStreamReader(zipFile.getInputStream(zipEntry), StandardCharsets.UTF_8);
char[] buffer = new char[8192];
StringWriter writer = new StringWriter();
int count;