Detail Bug Report
https://app.detail.dev/org_befd6425-a158-4e24-9d4d-1e5c08769515/bugs/bug_a0c5da3d-c713-46bf-a813-bcada1d2bdde
Summary
- Context:
RouteLocation is a domain model used to format coordinates as query parameters for the Apple Maps ETA and Directions APIs.
- Bug: The
fromLatitudeLongitude method uses Double.toString() to format coordinates, which produces scientific notation (e.g., "1.0E-4") for values with absolute magnitude less than 10^-3.
- Actual vs. expected: For coordinates near the equator or prime meridian (e.g., 0.0001), it produces strings like
"1.0E-4,1.0E-4" instead of the standard decimal format "0.0001,0.0001" required by the Apple Maps Server API.
- Impact: Routing and ETA requests for locations near the equator or prime meridian will fail as the API will be unable to parse the scientific notation in the query parameters.
Code with Bug
private static String formatCoordinatePair(double latitude, double longitude) {
return Double.toString(latitude) + COORDINATE_SEPARATOR + Double.toString(longitude); // <-- BUG 🔴 Uses scientific notation for small values
}
Explanation
Double.toString() switches to scientific notation for small-magnitude values (e.g., 0.0001 -> "1.0E-4"). When these strings are used in query parameters (e.g., toQueryString()), the resulting coordinate pair can include E notation, which the Apple Maps Server API expects as fixed-point decimal coordinates and may reject.
Codebase Inconsistency
Other tests (e.g., in EtaInputTest.java and DirectionsInputTest.java) implicitly assume decimal-formatted coordinates in query strings; they don’t cover near-zero values, so the scientific-notation case is currently untested.
Failing Test
package com.williamcallahan.applemaps.domain.model;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
class RouteLocationBugTest {
@Test
void fromLatitudeLongitudeProducesScientificNotationForSmallValues() {
// 0.0001 is formatted as "1.0E-4" by Double.toString()
RouteLocation loc = RouteLocation.fromLatitudeLongitude(0.0001, 0.0001);
String queryString = loc.toQueryString();
// Actual output: "1.0E-4,1.0E-4"
assertFalse(queryString.contains("E"), "Query string should not contain scientific notation: " + queryString);
}
}
Test failure:
RouteLocationBugTest > fromLatitudeLongitudeProducesScientificNotationForSmallValues() FAILED
org.opentest4j.AssertionFailedError: Query string should not contain scientific notation: 1.0E-4,1.0E-4
Recommended Fix
Format coordinates using fixed-point formatting (e.g., String.format or DecimalFormat) so query strings never contain scientific notation.
private static String formatCoordinatePair(double latitude, double longitude) {
return String.format("%.6f,%.6f", latitude, longitude);
}
History
This bug was introduced in commit 33eca2a. The commit added strongly-typed domain model records, including RouteLocation, but used Double.toString() for coordinate formatting.
Detail Bug Report
https://app.detail.dev/org_befd6425-a158-4e24-9d4d-1e5c08769515/bugs/bug_a0c5da3d-c713-46bf-a813-bcada1d2bdde
Summary
RouteLocationis a domain model used to format coordinates as query parameters for the Apple Maps ETA and Directions APIs.fromLatitudeLongitudemethod usesDouble.toString()to format coordinates, which produces scientific notation (e.g.,"1.0E-4") for values with absolute magnitude less than 10^-3."1.0E-4,1.0E-4"instead of the standard decimal format"0.0001,0.0001"required by the Apple Maps Server API.Code with Bug
Explanation
Double.toString()switches to scientific notation for small-magnitude values (e.g.,0.0001->"1.0E-4"). When these strings are used in query parameters (e.g.,toQueryString()), the resulting coordinate pair can includeEnotation, which the Apple Maps Server API expects as fixed-point decimal coordinates and may reject.Codebase Inconsistency
Other tests (e.g., in
EtaInputTest.javaandDirectionsInputTest.java) implicitly assume decimal-formatted coordinates in query strings; they don’t cover near-zero values, so the scientific-notation case is currently untested.Failing Test
Test failure:
Recommended Fix
Format coordinates using fixed-point formatting (e.g.,
String.formatorDecimalFormat) so query strings never contain scientific notation.History
This bug was introduced in commit 33eca2a. The commit added strongly-typed domain model records, including RouteLocation, but used
Double.toString()for coordinate formatting.