From 2f0c3e3a714355b28901bd7f56ad4bc265e121bf Mon Sep 17 00:00:00 2001 From: jcpitre Date: Mon, 15 Jan 2024 18:04:07 -0500 Subject: [PATCH 1/2] Corrected a problem where the version was null in the desktop version. --- .../gtfsvalidator/util/VersionResolver.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/main/src/main/java/org/mobilitydata/gtfsvalidator/util/VersionResolver.java b/main/src/main/java/org/mobilitydata/gtfsvalidator/util/VersionResolver.java index b9af1135c0..d6f3379828 100644 --- a/main/src/main/java/org/mobilitydata/gtfsvalidator/util/VersionResolver.java +++ b/main/src/main/java/org/mobilitydata/gtfsvalidator/util/VersionResolver.java @@ -5,8 +5,8 @@ import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.SettableFuture; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import io.github.classgraph.ClassGraph; import io.github.classgraph.Resource; import io.github.classgraph.ScanResult; @@ -151,19 +151,23 @@ private Optional resolveLatestReleaseVersion(Optional currentVer String.format( "%s?application_type=%s¤t_version=%s", LATEST_RELEASE_VERSION_URL, applicationType, currentVersion.orElse("Ï"))); + String jsonString = null; try (BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()))) { - Gson gson = new GsonBuilder().create(); - VersionResponse response = gson.fromJson(in, VersionResponse.class); - if (response != null && !Strings.isNullOrEmpty(response.version)) { - logger.atInfo().log("resolved release version=%s", response.version); - return Optional.of(response.version); + + // We expect the REST call to return something like : + // {"version":"1.4.0"} + jsonString = in.readLine(); + if (Strings.isNullOrEmpty(jsonString)) { + return Optional.empty(); } + + JsonObject json = JsonParser.parseString(jsonString).getAsJsonObject(); + String version = json.get("version").getAsString(); + return Optional.of(version); + } catch (Exception e) { + logger.atInfo().log("error parsing response=%s", jsonString); } - return Optional.empty(); - } - /** Serialization object for parsing the /version API response. */ - class VersionResponse { - String version; + return Optional.empty(); } } From 1fbfdb49129e9ffe9815a15cd85df3ac37993abb Mon Sep 17 00:00:00 2001 From: jcpitre Date: Tue, 16 Jan 2024 11:58:38 -0500 Subject: [PATCH 2/2] Modified the fix for a simpler solution. --- .../gtfsvalidator/util/VersionResolver.java | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/main/src/main/java/org/mobilitydata/gtfsvalidator/util/VersionResolver.java b/main/src/main/java/org/mobilitydata/gtfsvalidator/util/VersionResolver.java index d6f3379828..1e33fd3d0a 100644 --- a/main/src/main/java/org/mobilitydata/gtfsvalidator/util/VersionResolver.java +++ b/main/src/main/java/org/mobilitydata/gtfsvalidator/util/VersionResolver.java @@ -5,8 +5,8 @@ import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.SettableFuture; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import io.github.classgraph.ClassGraph; import io.github.classgraph.Resource; import io.github.classgraph.ScanResult; @@ -151,23 +151,19 @@ private Optional resolveLatestReleaseVersion(Optional currentVer String.format( "%s?application_type=%s¤t_version=%s", LATEST_RELEASE_VERSION_URL, applicationType, currentVersion.orElse("Ï"))); - String jsonString = null; try (BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()))) { - - // We expect the REST call to return something like : - // {"version":"1.4.0"} - jsonString = in.readLine(); - if (Strings.isNullOrEmpty(jsonString)) { - return Optional.empty(); + Gson gson = new GsonBuilder().create(); + VersionResponse response = gson.fromJson(in, VersionResponse.class); + if (response != null && !Strings.isNullOrEmpty(response.version)) { + logger.atInfo().log("resolved release version=%s", response.version); + return Optional.of(response.version); } - - JsonObject json = JsonParser.parseString(jsonString).getAsJsonObject(); - String version = json.get("version").getAsString(); - return Optional.of(version); - } catch (Exception e) { - logger.atInfo().log("error parsing response=%s", jsonString); } - return Optional.empty(); } + + /** Serialization object for parsing the /version API response. */ + public static class VersionResponse { + String version; + } }