Skip to content

Commit

Permalink
Merge pull request #513 from apjanke/fix-error-prone-warnings
Browse files Browse the repository at this point in the history
Fix Google Error Prone warnings
  • Loading branch information
domesticmouse committed Nov 24, 2018
2 parents ad89ee8 + 9aef3a7 commit 310d81e
Show file tree
Hide file tree
Showing 51 changed files with 69 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/DirectionsApiRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ public Waypoint(LatLng location, boolean isStopover) {
*
* @return The HTTP parameter fragment representing this waypoint.
*/
@Override
public String toString() {
if (isStopover) {
return location;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public String toUrlValue() {
public interface LocationBias extends UrlValue {}

public static class LocationBiasIP implements LocationBias {
@Override
public String toUrlValue() {
return "ipbias";
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/google/maps/GaeRequestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package com.google.maps;

import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.appengine.api.urlfetch.FetchOptions;
import com.google.appengine.api.urlfetch.HTTPHeader;
import com.google.appengine.api.urlfetch.HTTPMethod;
Expand Down Expand Up @@ -83,7 +85,7 @@ public <T, R extends ApiResponse<T>> PendingResult<T> handlePost(
try {
req = new HTTPRequest(new URL(hostName + url), HTTPMethod.POST, fetchOptions);
req.setHeader(new HTTPHeader("Content-Type", "application/json; charset=utf-8"));
req.setPayload(payload.getBytes());
req.setPayload(payload.getBytes(UTF_8));
} catch (MalformedURLException e) {
LOG.error("Request: {}{}", hostName, url, e);
throw (new RuntimeException(e));
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/google/maps/GeoApiContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,15 @@ <T, R extends ApiResponse<T>> PendingResult<T> get(
StringBuilder query = new StringBuilder();

boolean channelSet = false;
for (int i = 0; i < params.length; i++) {
for (int i = 0; i < params.length; i += 2) {
if (params[i].equals("channel")) {
channelSet = true;
}
query.append('&').append(params[i]).append('=');
i++;

// URL-encode the parameter.
try {
query.append(URLEncoder.encode(params[i], "UTF-8"));
query.append(URLEncoder.encode(params[i + 1], "UTF-8"));
} catch (UnsupportedEncodingException e) {
// This should never happen. UTF-8 support is required for every Java implementation.
throw new IllegalStateException(e);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/OkHttpRequestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public <T, R extends ApiResponse<T>> PendingResult<T> handlePost(
req, client, clazz, fieldNamingPolicy, errorTimeout, maxRetries, exceptionsAllowedToRetry);
}

@Override
public void shutdown() {
executorService.shutdown();
client.connectionPool().evictAll();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/google/maps/StaticMapsRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public StaticMapsRequest(GeoApiContext context) {

@Override
protected void validateRequest() {
if (!(params().containsKey("center") && params().containsKey("zoom")
if (!((params().containsKey("center") && params().containsKey("zoom"))
|| params().containsKey("markers"))) {
throw new IllegalArgumentException(
"Request must contain 'center' and 'zoom' if 'markers' isn't present.");
Expand Down Expand Up @@ -139,6 +139,7 @@ public enum StaticMapType implements UrlValue {
terrain,
hybrid;

@Override
public String toUrlValue() {
return this.name();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/google/maps/internal/PolylineEncoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static String encode(final List<LatLng> path) {
long lastLat = 0;
long lastLng = 0;

final StringBuffer result = new StringBuffer();
final StringBuilder result = new StringBuilder();

for (final LatLng point : path) {
long lat = Math.round(point.lat * 1e5);
Expand All @@ -87,7 +87,7 @@ public static String encode(final List<LatLng> path) {
return result.toString();
}

private static void encode(long v, StringBuffer result) {
private static void encode(long v, StringBuilder result) {
v = v < 0 ? ~(v << 1) : v << 1;
while (v >= 0x20) {
result.append(Character.toChars((int) ((0x20 | (v & 0x1f)) + 63)));
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/google/maps/internal/UrlSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package com.google.maps.internal;

import static java.nio.charset.StandardCharsets.UTF_8;

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Mac;
Expand Down Expand Up @@ -48,7 +50,7 @@ public UrlSigner(final String keyString) throws NoSuchAlgorithmException, Invali

/** Generate url safe HmacSHA1 of a path. */
public String getSignature(String path) {
byte[] digest = getMac().doFinal(path.getBytes());
byte[] digest = getMac().doFinal(path.getBytes(UTF_8));
return ByteString.of(digest).base64().replace('+', '-').replace('/', '_');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ private LongMath() {}
* Returns the sum of {@code a} and {@code b} unless it would overflow or underflow in which case
* {@code Long.MAX_VALUE} or {@code Long.MIN_VALUE} is returned, respectively.
*/
/* Suppress warnings instead of "fixing" because this is code imported from Guava. */
@SuppressWarnings("ShortCircuitBoolean")
public static long saturatedAdd(long a, long b) {
long naiveSum = a + b;
if ((a ^ b) < 0 | (a ^ naiveSum) >= 0) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/AddressComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class AddressComponent implements Serializable {
/** Indicates the type of each part of the address. Examples include street number or country. */
public AddressComponentType[] types;

@Override
public String toString() {
StringBuilder sb = new StringBuilder("[AddressComponent: ");
sb.append("\"").append(longName).append("\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public static class MatchedSubstring {
/** The start position of the matched substring, measured in Unicode characters. */
public int offset;

@Override
public String toString() {
return String.format("(offset=%d, length=%d)", offset, length);
}
Expand All @@ -90,11 +91,13 @@ public static class Term {
/** The text of the matched term. */
public String value;

@Override
public String toString() {
return String.format("(offset=%d, value=%s)", offset, value);
}
}

@Override
public String toString() {
return String.format(
"[AutocompletePrediction: \"%s\", placeId=%s, types=%s, terms=%s, "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class AutocompleteStructuredFormatting implements Serializable {
/** The secondary text of a prediction, usually the location of the place. */
public String secondaryText;

@Override
public String toString() {
StringBuilder sb = new StringBuilder("(");
sb.append("\"").append(mainText).append("\"");
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/Bounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class Bounds implements Serializable {
/** The southwest corner of the bounding box. */
public LatLng southwest;

@Override
public String toString() {
return String.format("[%s, %s]", northeast, southwest);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/CellTower.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private CellTower(
/** The timing advance value. */
public Integer timingAdvance = null;

@Override
public String toString() {
return String.format(
"[CellTower: cellId=%s, locationAreaCode=%s, mobileCountryCode=%s, "
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/DirectionsLeg.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public class DirectionsLeg implements Serializable {
*/
public String endAddress;

@Override
public String toString() {
StringBuilder sb =
new StringBuilder(
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/DirectionsRoute.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class DirectionsRoute implements Serializable {
*/
public String[] warnings;

@Override
public String toString() {
String str =
String.format(
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/DirectionsStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public class DirectionsStep implements Serializable {
*/
public TransitDetails transitDetails;

@Override
public String toString() {
StringBuilder sb = new StringBuilder("[DirectionsStep: ");
sb.append("\"").append(htmlInstructions).append("\"");
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/DistanceMatrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public DistanceMatrix(
this.rows = rows;
}

@Override
public String toString() {
return String.format(
"DistanceMatrix: %d origins x %d destinations, %d rows",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class DistanceMatrixElement implements Serializable {
/** {@code fare} contains information about the fare (that is, the ticket costs) on this route. */
public Fare fare;

@Override
public String toString() {
String str =
String.format(
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/DistanceMatrixRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class DistanceMatrixRow implements Serializable {
/** The results for this row, or individual origin. */
public DistanceMatrixElement[] elements;

@Override
public String toString() {
return String.format("[DistanceMatrixRow %d elements]", elements.length);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/ElevationResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class ElevationResult implements Serializable {
/** Maximum distance between data points from which the elevation was interpolated, in meters. */
public double resolution;

@Override
public String toString() {
return String.format("(%s, %f m, resolution=%f m)", location, elevation, resolution);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/EncodedPolyline.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public List<LatLng> decodePath() {

// Use the encoded point representation; decoding to get an alternate representation for
// individual points would be expensive.
@Override
public String toString() {
return String.format("[EncodedPolyline: %s]", points);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/Fare.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Fare implements Serializable {
/** The total fare amount, in the currency specified in {@link #currency}. */
public BigDecimal value;

@Override
public String toString() {
return String.format("%s %s", value, currency);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/FindPlaceFromText.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class FindPlaceFromText implements Serializable {

public PlacesSearchResult candidates[];

@Override
public String toString() {
return String.format("[FindPlaceFromText %d candidates]", candidates.length);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/GeocodedWaypoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class GeocodedWaypoint implements Serializable {
/** The address types of the geocoding result used for calculating directions. */
public AddressType types[];

@Override
public String toString() {
StringBuilder sb = new StringBuilder("[GeocodedWaypoint");
sb.append(" ").append(geocoderStatus);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/GeocodingResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class GeocodingResult implements Serializable {
/** The Plus Code identifier for this place. */
public PlusCode plusCode;

@Override
public String toString() {
StringBuilder sb = new StringBuilder("[GeocodingResult");
if (partialMatch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private GeolocationPayload(
/** An array of WiFi access point objects. See {@link com.google.maps.model.WifiAccessPoint}. */
public WifiAccessPoint[] wifiAccessPoints;

@Override
public String toString() {
StringBuilder sb = new StringBuilder("[GeolocationPayload");
List<String> elements = new ArrayList<>();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/GeolocationResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class GeolocationResult implements Serializable {
*/
public double accuracy;

@Override
public String toString() {
return String.format("%s, accuracy=%s m", location, accuracy);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/Geometry.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class Geometry implements Serializable {
*/
public Bounds viewport;

@Override
public String toString() {
return String.format(
"[Geometry: %s (%s) bounds=%s, viewport=%s]", location, locationType, bounds, viewport);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/google/maps/model/OpeningHours.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public String getName() {
/** Time that this Open or Close happens at. */
public LocalTime time;

@Override
public String toString() {
return String.format("%s %s", day, time);
}
Expand All @@ -86,6 +87,7 @@ public String toString() {
/** When the Place closes. */
public Period.OpenClose close;

@Override
public String toString() {
return String.format("%s - %s", open, close);
}
Expand All @@ -107,6 +109,7 @@ public String toString() {
*/
public Boolean permanentlyClosed;

@Override
public String toString() {
StringBuilder sb = new StringBuilder("[OpeningHours:");
if (permanentlyClosed != null && permanentlyClosed) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/Photo.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class Photo implements Serializable {
/** Attributions about this listing which must be displayed to the user. */
public String[] htmlAttributions;

@Override
public String toString() {
String str = String.format("[Photo %s (%d x %d)", photoReference, width, height);
if (htmlAttributions != null && htmlAttributions.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public enum PlaceAutocompleteType implements StringJoin.UrlValue {
this.placeType = placeType;
}

private String placeType;
private final String placeType;

@Override
public String toUrlValue() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/google/maps/model/PlaceDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public static class AlternatePlaceIds implements Serializable {
*/
public PlaceIdScope scope;

@Override
public String toString() {
return String.format("%s (%s)", placeId, scope);
}
Expand Down Expand Up @@ -222,6 +223,7 @@ public enum RatingType {
/** Attributions about this listing which must be displayed to the user. */
public String[] htmlAttributions;

@Override
public String toString() {
StringBuilder sb = new StringBuilder("[PlaceDetails: ");
sb.append("\"").append(name).append("\"");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/google/maps/model/PlaceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public enum PlaceType implements StringJoin.UrlValue {
this.placeType = placeType;
}

private String placeType;
private final String placeType;

@Override
public String toUrlValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class PlacesSearchResponse implements Serializable {
*/
public String nextPageToken;

@Override
public String toString() {
StringBuilder sb = new StringBuilder("[PlacesSearchResponse: ");
sb.append(results.length).append(" results");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class PlacesSearchResult implements Serializable {
/** Indicates that the place has permanently shut down. */
public boolean permanentlyClosed;

@Override
public String toString() {
StringBuilder sb = new StringBuilder("[PlacesSearchResult: ");
sb.append("\"").append(name).append("\"");
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/PlusCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class PlusCode {
/** The compound Plus Code identifier. May be null for locations in remote areas. */
public String compoundCode;

@Override
public String toString() {
StringBuilder sb = new StringBuilder("[PlusCode: ");
sb.append(globalCode);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/maps/model/SnappedPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class SnappedPoint implements Serializable {
*/
public String placeId;

@Override
public String toString() {
return String.format("[%s, placeId=%s, originalIndex=%s]", location, placeId, originalIndex);
}
Expand Down
Loading

0 comments on commit 310d81e

Please sign in to comment.