Fix IDE 324 : ClassCastException in DataListFragment and stabilize UI tests#5177
Conversation
|
@wslany Could you please add this PR issue to a Jira ticket? Apologies for raising the PR without linking one. If possible, may I create the ticket for this? |
wslany
left a comment
There was a problem hiding this comment.
@wslany Could you please add this PR issue to a Jira ticket? Apologies for raising the PR without linking one. If possible, may I create the ticket for this? Thanks!
Thanks for the follow-up PR. Yes, I would be grateful if you could create the ticket for it. If you can't yet create it, let me set it up for you. I'll also look into how you can get write access to our jira.
I checked the changes and also ran the focused FormulaEditorUndoTest suite locally.
The good part first: the ClassCastException root cause analysis makes sense, and the new popup-menu test interactions (inRoot(isPlatformPopup())) are a nice stability improvement.
One thing I would still like to revisit in the production code, though, is that this seems to fix the symptom rather than the underlying type mismatch. DataListFragment is still declared as T : UserData, while UserVariable is actually UserData. The new UserData<*> cast in showEditDialog() and the UserVariable special case in editItem() avoid the current crash, but the model is still inconsistent. I think it would be safer to widen the fragment’s generic type / value handling more explicitly instead of relying on local casts.
On the tests: when I ran FormulaEditorUndoTest on this PR branch by itself, most of the suite was still red because of the already-known undo-button visibility issue on current develop. That looks expected to me, since this follow-up branch is based on develop and does not include the production undo fix from #5171. So I would evaluate this PR mainly as a follow-up to #5171, not as a standalone green fix on current develop.
So from my side:
- the test helper changes look good
- the crash fix direction is reasonable
- but I would prefer one more refinement on the DataListFragment typing rather than keeping the current cast-based workaround as-is
Yes, thank you! I’d appreciate that. |
@wslany Thanks for the detailed feedback! I agree that the current approach relies on a cast-based workaround. I’ll take another pass to improve the type handling in DataListFragment and make the solution more robust and type-safe. |
There was a problem hiding this comment.
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
17a6f17 to
e14f088
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wslany
left a comment
There was a problem hiding this comment.
Thanks for the update. I found one issue that I think should be fixed before merging:
DataListFragment now uses ShowTextUtils.convertObjectToString(item.value) to prefill the edit dialog, but editItem() only parses plain Double values. That means display-formatted values can be written back into the model as strings if the user opens Edit and presses Save without changing anything.
Examples:
1000is displayed as1k, then saved back as"1k"1000000is displayed as1M, then saved back as"1M"- boolean values are displayed as localized true/false strings, then saved back as strings
This silently changes the UserVariable value type and can break formula behavior that depends on Number or Boolean values.
I think the safest fix is to prefill the edit field with a persistence-safe raw value instead of the display-formatted string, or alternatively make the save path parse exactly the same formats that the display path emits.
|
Thanks for the update. The previous display-formatted round-trip issue looks fixed now. I found one smaller follow-up issue in val trimmedValue = value?.trim()
...
} catch (_: NumberFormatException) {
trimmedValue
}This trims every edited value before deciding what to store. That is fine for numeric/boolean parsing, but when parsing falls back to a string it now stores trimmedValue, so a string variable containing leading or trailing spaces is silently changed just by opening Edit and pressing Save. Could you use a trimmed copy only for the numeric/boolean checks, but fall back to the original value when the input is meant to remain a string, including tests to document the intended behavior? |
|
@wslany PTAL |
|
… UserVariable.setValue
Swap expected/actual arguments in all assertEquals calls to follow JUnit convention: assertEquals(expected, actual[, delta]). Previously the project value was passed as expected and the constant as actual, which would produce misleading failure messages.
…matted string showEditDialog() previously used ShowTextUtils.convertObjectToString() which formats values for display (e.g. 1000→1k, true→localized string). Since editItem() only parses Double, pressing Save without edits would silently convert the value type from Double/Boolean to String. Now prefills the edit field with a persistence-safe raw representation and extends editItem() to also parse boolean literals, preserving value types on roundtrip.
6861401 to
2cb791e
Compare
wslany
left a comment
There was a problem hiding this comment.
Thanks for the updates. I rechecked the rebased PR, ran the focused FormulaEditorUndo and DataListFragment user-variable UI tests locally, and installed a clearly labeled build for manual verification. The previous value round-trip issues are fixed, CI is green, and manual testing looked good.
Approved from my side.
721ce30 to
ec95e03
Compare
|



JIRA TICKET - https://catrobat.atlassian.net/browse/IDE-324
Description:
This pull request addresses a
ClassCastExceptioninDataListFragmentand resolves test regressions within theFormulaEditorUndoTest. Additionally, it stabilizes UI interactions for Espresso tests involving platform popups.Note: This pull request is a continuation of (#5171)
Detailed Changes
1. Fixed
ClassCastExceptioninDataListFragment.ktDataListFragmenthad a type-safety issue when trying to update user variables, which could lead to aClassCastExceptionor incorrect data types being saved.UserVariabletypes ineditItem. It now intelligently tries to parse the input value as aDoublefirst (for numeric variables) and falls back to aStringif it's not a number. This ensures the underlying data model remains consistent.2. Resolved
FormulaEditorUndoTestRegressionscloseSoftKeyboard()calls to prevent the soft keyboard from obstructing the view during automated tests. Updated numeric assertions to use a delta comparison (assertEquals(expected, actual, 0.001)), making the tests more robust against minor precision differences in floating-point math.3. Stabilized UI Test Interactions
UserDataItemRVInteractionWrapper.javato explicitly search for these buttons within the platform popup root (isPlatformPopup()). This prevents common "No Matching View" errors in UI tests.Files Modified:
DataListFragment.kt: UpdatededitFieldandeditItemlogic.FormulaEditorUndoTest.java: Improved test stability and assertions.UserDataItemRVInteractionWrapper.java: Fixed popup menu interaction logic.Checklist for this pull request
Please review the contributing guidelines and wiki pages of this repository.