Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: app crash due to IllegalArgumentException in SearchFragment #1394

Merged
merged 1 commit into from
Mar 24, 2019

Conversation

addiegupta
Copy link
Contributor

@addiegupta addiegupta commented Mar 24, 2019

Fixes: #1383

Changes:

  • A default value of 'null' has been assigned to the argument 'saved_date'.
  • This resolves the crash as the SearchFragmentArgs generated files throws an IllegalArgumentException if this argument
    does not exist in the bundle with which it is initialised in its 'fromBundle' method. Now a null value is passed and hence the crash
    does not occur.
  • Additionally 2 hardcoded strings have been replaced with their resource reference equivalents

The code in SearchFragmentArgs that was throwing the exception is :

if (bundle.containsKey("@string/saved_date")) {
// code that inserts it in arguments, redacted for simplicity
} else {
throw new IllegalArgumentException("Required argument \"@string/saved_date\" is missing and does not have an android:defaultValue");
}

After adding the android:defaultValue="@null" property to the navigation.xml file, this IllegalArgumentException statement appears to have gone from the generated file

Screenshots for the change:

PR 1383

Fixes:fossasia#1383

- A default value of 'null' has been assigned to the argument 'saved_date'.
- This resolves the crash as the SearchFragmentArgs generated files throws an IllegalArgumentException if this argument
does not exist in the bundle with which it is initialsed in its 'fromBundle' method. Now a null value is passed and hence the crash
does not occur.
- Additionally 2 hardcoded strings have been replaced with their resource reference equivalents
@@ -105,7 +105,7 @@ class SearchTimeFragment : Fragment() {
}

private fun redirectToSearch(time: String) {
val args = SearchFragmentArgs.Builder(time).build().toBundle()
val args = SearchFragmentArgs.Builder().setStringSavedDate(time).build().toBundle()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made this change because for some reason that I could not find, the constructor for SearchFragmentArgs.Builder that takes a string as an argument appears to be missing from the generated file of SearchFragmentArgs.java

This is the missing constructor:

public Builder(@Nullable String StringSavedDate) { this.arguments.put("@string/saved_date", StringSavedDate); }

@iamareebjamal iamareebjamal merged commit 7c22ee0 into fossasia:development Mar 24, 2019
@addiegupta addiegupta deleted the 1383 branch March 24, 2019 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

App crashing due to IllegalArgumentException
2 participants