fix: resolve nullPointerException issue #1458
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm Akash kumar , a contributor working on the OneBusAway. This pull request fixes #1278 by adding null-safety checks to prevent NullPointerException errors when handling null format arguments in string resources.
Changes Made:
Null Argument Handling: Added safeGetString() utility method in UIUtils.java that replaces any null elements in format arguments with empty strings before calling Context.getString(). This prevents formatting errors and unwanted "null" text from appearing in UI strings.
Implementation: The method iterates through the varargs array and converts null values to empty strings, ensuring the string resource formatter always receives valid arguments.
I tested this by simulating null format arguments in various string resource calls throughout the codebase, and it successfully prevents crashes while maintaining clean UI text display.
Apply the
AndroidStyle.xmlstyle template to your code in Android Studio.Run the unit tests with
gradlew connectedObaGoogleDebugAndroidTestto make sure you didn't break anythingIf you have multiple commits please combine them into one commit by squashing them for the initial submission of the pull request. When addressing comments on a pull request, please push a new commit per comment when possible (reviewers will squash and merge using GitHub merge tool)