Skip to content

CATROID-1654 Fix startup crash by hardening project parsing and room upgrade#5203

Merged
urkat merged 12 commits into
Catrobat:release-1.4.0from
wslany:codex/fix-release-1.4.0-project-metadata-startup-crash
Apr 27, 2026
Merged

CATROID-1654 Fix startup crash by hardening project parsing and room upgrade#5203
urkat merged 12 commits into
Catrobat:release-1.4.0from
wslany:codex/fix-release-1.4.0-project-metadata-startup-crash

Conversation

@wslany

@wslany wslany commented Apr 22, 2026

Copy link
Copy Markdown
Member

Summary
This PR prevents startup crashes after app updates in two related startup paths:

  1. malformed legacy project metadata (code.xml)
  2. legacy featured-project cache database schema mismatch

https://catrobat.atlassian.net/browse/CATROID-1654

What changed

  1. Added regression tests for invalid metadata parsing in ProjectMetaDataParserTest.

  2. Hardened ProjectMetaDataParser to:

    • reject missing/blank programName
    • convert runtime parse failures into IOException consistently
  3. Hardened startup project scan in MainFragmentViewModel:

    • catch and skip metadata parse failures (IOException)
    • include metadata file path in log output
  4. Added Room database upgrade handling for featured-project cache data:

    • bumped AppDatabase version 2 -> 3
    • added MIGRATION_2_3 and wired it in Koin database builder
    • migration safely rebuilds cache/synced tables (featured_project, project_response, project_category)
    • added migration regression test and schema 3.json

Why
On upgraded installs with legacy/corrupted project metadata, startup scan could fail before the user reaches the main UI.
Additionally, some upgraded installs had a legacy Room identity hash (c60ebf...) while current code expects (2d6dd...), causing startup termination when opening the featured-project cache DB.

Behavior after fix

App startup remains stable even if one or more project metadata files are broken.
Broken project metadata entries are skipped; valid projects still load.
Featured-project cache DB is migrated/rebuilt on upgrade without deleting user projects.

Testing

:catroid:testCatroidDebugUnitTest --tests "org.catrobat.catroid.test.content.backwardcompatibility.ProjectMetaDataParserTest" --no-daemon
:catroid:testCatroidDebugUnitTest --tests "org.catrobat.catroid.test.content.backwardcompatibility.*" --no-daemon
:catroid:testCatroidDebugUnitTest --tests "org.catrobat.catroid.db.DatabaseMigrationsTest" --no-daemon

Your checklist for this pull request

Please review the contributing guidelines and wiki pages of this repository.

  • Include the name of the Jira ticket in the PR's title
  • Include a summary of the changes plus the relevant context
  • Choose the proper base branch (release-1.4.0)
  • Confirm that the changes follow the project's coding guidelines
  • Verify that the changes generate no compiler or linter warnings
  • Perform a self-review of the changes
  • Verify to commit no other files than the intentionally changed ones
  • Include reasonable and readable tests verifying the added or changed behavior
  • Confirm that new and existing unit tests pass locally
  • Check that the commits' message style matches the project's guideline
  • Stick to the project's gitflow workflow
  • Verify that your changes do not have any conflicts with the base branch
  • After the PR, verify that all CI checks have passed
  • Post a message in the catroid-stage or catroid-ide Slack channel and ask for a code reviewer

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Hardens legacy code.xml project metadata parsing to prevent app startup crashes when encountering malformed or corrupted project metadata after upgrades.

Changes:

  • Added unit tests for invalid/missing programName handling in legacy metadata parsing.
  • Updated ProjectMetaDataParser to validate programName and normalize runtime parsing failures into IOException.
  • Updated startup project scan in MainFragmentViewModel to skip/log projects whose metadata cannot be parsed (including file path in logs).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
catroid/src/test/java/org/catrobat/catroid/test/content/backwardcompatibility/ProjectMetaDataParserTest.java Adds regression tests for invalid metadata inputs (missing/blank programName).
catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/viewmodel/MainFragmentViewModel.kt Hardens startup scan by catching parsing failures and logging the failing metadata path.
catroid/src/main/java/org/catrobat/catroid/content/backwardcompatibility/ProjectMetaDataParser.java Adds validation for required fields and wraps runtime XStream parse failures into IOException.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread catroid/src/main/java/org/catrobat/catroid/db/DatabaseMigrations.kt Fixed
@wslany

wslany commented Apr 23, 2026

Copy link
Copy Markdown
Member Author

I investigated the device crash log from the update-repro setup and found a second startup crash that is separate from the project XML parsing fix.

Root cause from logcat:

  • IllegalStateException: Room cannot verify the data integrity
  • expected identity hash: 2d6dd2073b5265cd9e3920e29b07c537
  • found: c60ebf67428479ff4619d56d1eb30d08

This happens in AppDatabase when opening project_response/featured cache tables. It is an old schema (without private) being opened by code expecting the newer schema.

I pushed a follow-up on this PR branch:

  • [test] add migration regression test
  • [fix] bump AppDatabase to version 3 + add MIGRATION_2_3 that rebuilds featured-project cache tables safely
  • wire migration in Koin builder
  • add Room schema file 3.json

This migration only rebuilds synced/cache data tables, not user projects, so it should prevent startup crash on update without requiring full app data deletion.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread catroid/src/main/java/org/catrobat/catroid/db/AppDatabase.kt
Comment thread catroid/src/test/java/org/catrobat/catroid/db/DatabaseMigrationsTest.kt Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wslany wslany marked this pull request as ready for review April 23, 2026 06:52
@wslany wslany changed the title CATROID-1654 Fix startup crash by hardening project metadata parsing CATROID-1654 Fix startup crash by hardening project parsing and room upgrade Apr 23, 2026
@wslany wslany marked this pull request as draft April 23, 2026 10:41
@wslany wslany force-pushed the codex/fix-release-1.4.0-project-metadata-startup-crash branch from e07f75f to 6bdaadf Compare April 23, 2026 11:35
@wslany wslany marked this pull request as ready for review April 23, 2026 11:37
@wslany

wslany commented Apr 23, 2026

Copy link
Copy Markdown
Member Author

I confirmed the crash before the fix consistently on my phone, then updated to the fixed version (with the same package name) and observed no crash anymore. I also tested the fixed APK along other aspects and found no obvious deficiencies.

@reichli reichli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only found one problem with a test that I could not run.

The rest of the PR looks good! Database migration + tests look good.
I was also able to reproduce the crash and fix it with this PR.

@sonarqubecloud

Copy link
Copy Markdown

@wslany wslany requested a review from reichli April 23, 2026 19:19

@reichli reichli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved - thank you very much!

@wslany wslany added Hotfix Active Member Tickets that are assigned to members that are still currently active labels Apr 25, 2026
@urkat urkat merged commit a0a5937 into Catrobat:release-1.4.0 Apr 27, 2026
16 checks passed
@wslany wslany deleted the codex/fix-release-1.4.0-project-metadata-startup-crash branch April 28, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Active Member Tickets that are assigned to members that are still currently active Hotfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants