Skip to content

Commit

Permalink
UpgradeChecker: more thorough check of upgrade check result and HTTP …
Browse files Browse the repository at this point in the history
…response code

This tries to handle the cases where the result of the upgrade check is non-empty
string indicating that something went wrong.
  • Loading branch information
melissalinkert committed Dec 13, 2024
1 parent 2f26848 commit ea27aac
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions components/formats-bsd/src/loci/formats/UpgradeChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
Expand Down Expand Up @@ -227,7 +228,7 @@ public boolean newVersionAvailable(String registryID, String caller) {
try {
// connect to the registry

URLConnection conn = new URL(query.toString()).openConnection();
HttpURLConnection conn = (HttpURLConnection) new URL(query.toString()).openConnection();
conn.setConnectTimeout(5000);
conn.setUseCaches(false);
conn.addRequestProperty("User-Agent", registryID);
Expand All @@ -248,12 +249,19 @@ public boolean newVersionAvailable(String registryID, String caller) {
// check if the string is not empty (upgrade available)

String result = sb.toString();
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
LOGGER.debug("Upgrade check failed: {}", result);
return false;
}
if (sb.length() == 0) {
LOGGER.debug("No update needed");
return false;
} else {
LOGGER.debug("UPGRADE AVAILABLE:" + result);
} else if (result.toLowerCase().indexOf("please upgrade") >= 0) {
LOGGER.debug("UPGRADE AVAILABLE: {}", result);
return true;
} else {
LOGGER.debug("Upgrade check not successful: {}", result);
return false;
}
}
catch (UnknownHostException e) {
Expand Down

0 comments on commit ea27aac

Please sign in to comment.