@@ -129,23 +129,41 @@ private static StatusResult getStatus() {
129129
130130 // 1. Network Check
131131 NetworkResult networkResult = fetchFromNetwork (statusUrl , cachedTime );
132- if (networkResult != null ) {
133- if (networkResult .responseCode () == HttpURLConnection .HTTP_NOT_MODIFIED ) {
134- try (var fis = AppApplication .app .openFileInput (CACHE_FILE )) {
135- var cacheJson = parseStatus (fis );
136- publishTime = new Date (cachedTime );
137- return new StatusResult (cacheJson .getJSONObject ("entries" ), DataSource .NETWORK_UP_TO_DATE );
138- } catch (Exception e ) {
139- Log .w (TAG , "Failed to read cache despite 304 response. Falling back." , e );
132+
133+ if (networkResult != null && networkResult .responseCode () == HttpURLConnection .HTTP_NOT_MODIFIED ) {
134+ try (var fis = AppApplication .app .openFileInput (CACHE_FILE )) {
135+ var cacheJson = parseStatus (fis );
136+ publishTime = new Date (cachedTime );
137+ return new StatusResult (cacheJson .getJSONObject ("entries" ), DataSource .NETWORK_UP_TO_DATE );
138+ } catch (Exception e ) {
139+ Log .w (TAG , "Legacy cache format detected. Clearing and forcing fresh fetch." , e );
140+
141+ // 1. Wipe the old, incompatible cache file
142+ AppApplication .app .deleteFile (CACHE_FILE );
143+
144+ // 2. Wipe the saved timestamp so we don't send If-Modified-Since again
145+ prefs .edit ().remove (KEY_PUBLISH_TIME ).apply ();
146+
147+ // 3. Immediately force a fresh 200 OK download
148+ NetworkResult retryResult = fetchFromNetwork (statusUrl , 0 );
149+
150+ if (retryResult != null && retryResult .json () != null ) {
151+ saveToCache (retryResult .json ());
152+
153+ try {
154+ return new StatusResult (retryResult .json ().getJSONObject ("entries" ), DataSource .NETWORK_UPDATE );
155+ } catch (JSONException je ) {
156+ Log .e (TAG , "Failed to parse entries from fresh fallback fetch" , je );
157+ }
140158 }
141- } else if (networkResult .json () != null ) {
142- saveToCache (networkResult .json ());
143- try {
144- return new StatusResult (networkResult .json ().getJSONObject ("entries" ), DataSource .NETWORK_UPDATE );
145- } catch (JSONException ignored ) {}
146159 }
160+ } else if (networkResult != null && networkResult .json () != null ) {
161+ saveToCache (networkResult .json ());
162+ try {
163+ return new StatusResult (networkResult .json ().getJSONObject ("entries" ), DataSource .NETWORK_UPDATE );
164+ } catch (JSONException ignored ) {}
147165 }
148-
166+
149167 // 2. Cache
150168 try (var fis = AppApplication .app .openFileInput (CACHE_FILE )) {
151169 var cacheJson = parseStatus (fis );
0 commit comments