Fixed
Status Update
Comments
da...@google.com <da...@google.com> #2
Hi. Thanks for reporting this. Fixed in alpha-04
kp...@gmail.com <kp...@gmail.com> #3
Project: platform/frameworks/support
Branch: androidx-main
commit e782987543a9f8ccd485e970ddc74564b24378db
Author: Vighnesh Raut <vighnesh.raut13@gmail.com>
Date: Mon Jan 02 15:27:40 2023
fix: tab row crashes when only 1 tab is added
Bug: b/264018028
Test: Added unit test
Change-Id: I6381dbac304fc1d69d3708c6655f8b595668e93f
M tv/tv-material/src/androidTest/java/androidx/tv/material/TabRowTest.kt
M tv/tv-material/src/main/java/androidx/tv/material/TabRow.kt
https://android-review.googlesource.com/2373449
Branch: androidx-main
commit e782987543a9f8ccd485e970ddc74564b24378db
Author: Vighnesh Raut <vighnesh.raut13@gmail.com>
Date: Mon Jan 02 15:27:40 2023
fix: tab row crashes when only 1 tab is added
Bug:
Test: Added unit test
Change-Id: I6381dbac304fc1d69d3708c6655f8b595668e93f
M tv/tv-material/src/androidTest/java/androidx/tv/material/TabRowTest.kt
M tv/tv-material/src/main/java/androidx/tv/material/TabRow.kt
da...@google.com <da...@google.com> #4
deleted
ap...@google.com <ap...@google.com> #5
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.tv:tv-material:1.0.0-alpha04
Description
Version used: Room 2.0.0-alpha05
Devices/Android versions reproduced on: Any
Recent deprecations influence business logic flow a lot. Example: remote server's response parsing (I think, rather common case).
Old way:
// JSONException is thrown upper, so it can be managed alltogether with HTTP response errors (for example, just ignored to use old data on unexpected response format)
public void parseResponse(final JSONObject obj, final JSONArray subObjs) throws JSONException
{
db.beginTransaction();
try {
final DBItem item = db.getDaoItem().findItem(obj.getLong("id"));
item.parseSomehow(obj); // throws JSONException on failure
final DBSubItem[] subitems = db.getDaoSubItem().findSubItems(item.getId());
db.getDaoSubItem().replaceSubItems(item.getId(), DBSubItem.parseSomehow(subObjs)); // replaces, reusing subitems with updating inner order; throws JSONException on failure
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
New way (looks worse, no exception type control - so you can throw anything and check it only in runtime):
public void parseResponse(final JSONObject obj, final JSONArray subObjs) throws JSONException
{
try {
db.runInTransaction(() -> {
... // same code as in previous example inside try...catch
return null;
});
} catch (RuntimeException e) {
if (e.getCause() instanceof JSONException) {
throw (JSONException)e.getCause();
} else {
throw e;
}
}
}
Of course, I can try to separate parsing from database interaction, but it would require at least temporary objects with no more usage (in the project's code). Additionally, sometimes next parsing steps depend on previous / storage data.
Final thoughts. Looks like runInTransaction should be recommended method in most situations, but the old way is still convenient too.