Skip to content

Commit

Permalink
style: Fix 2 ErrorProneStyle findings (#591)
Browse files Browse the repository at this point in the history
* Constructors and methods with the same name should appear sequentially with no other code in between.
* This catch block catches an exception and re-throws another, but swallows the caught exception rather than setting it as a cause. This can make debugging harder.

Courtesy of clshepherd/clrobot in the monorepo.

Fixes #590.
  • Loading branch information
Capstan authored Aug 3, 2022
1 parent ad467ef commit 5e4e732
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,16 @@ public static Value.Builder makeValue(Date date) {
return Value.newBuilder().setTimestampValue(toTimestamp(date.getTime() * 1000L));
}

/** Makes a GeoPoint value. */
public static Value.Builder makeValue(LatLng value) {
return Value.newBuilder().setGeoPointValue(value);
}

/** Makes a GeoPoint value. */
public static Value.Builder makeValue(LatLng.Builder value) {
return makeValue(value.build());
}

private static Timestamp.Builder toTimestamp(long microseconds) {
long seconds = microseconds / MICROSECONDS_PER_SECOND;
long microsecondsRemainder = microseconds % MICROSECONDS_PER_SECOND;
Expand All @@ -497,16 +507,6 @@ private static Timestamp.Builder toTimestamp(long microseconds) {
.setNanos((int) microsecondsRemainder * NANOSECONDS_PER_MICROSECOND);
}

/** Makes a GeoPoint value. */
public static Value.Builder makeValue(LatLng value) {
return Value.newBuilder().setGeoPointValue(value);
}

/** Makes a GeoPoint value. */
public static Value.Builder makeValue(LatLng.Builder value) {
return makeValue(value.build());
}

/**
* Make a key from the specified path of kind/id-or-name pairs and/or Keys.
*
Expand Down Expand Up @@ -545,7 +545,8 @@ public static Key.Builder makeKey(Object... elements) {
try {
kind = (String) element;
} catch (ClassCastException e) {
throw new IllegalArgumentException("Expected string or Key, got: " + element.getClass());
throw new IllegalArgumentException(
"Expected string or Key, got: " + element.getClass(), e);
}
pathElement.setKind(kind);
if (pathIndex + 1 < elements.length) {
Expand Down

0 comments on commit 5e4e732

Please sign in to comment.