put country setters in right places#225
Merged
andrewbaxter439 merged 1 commit intodevelopfrom Aug 8, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes country setter placement by moving the Country.getCountryFromNameString(countryString) assignment to occur before it's used in the database lookup, addressing issue #224.
- Moves country initialization to happen before the country variable is used in line 89
- Adds country initialization in the exception handler to ensure it's always set
Comment on lines
+88
to
+94
| country = Country.getCountryFromNameString(countryString); | ||
| String valueYear = lastDatabaseCountryAndYear.getValue(country.toString()).toString(); | ||
| startYear = Integer.parseInt(valueYear); | ||
| } catch (NullPointerException e) { | ||
| System.out.println("No last database country and year found."); | ||
| countryString = "United Kingdom"; | ||
| country = Country.getCountryFromNameString(countryString); |
There was a problem hiding this comment.
The country variable is used here but may still be null if an exception occurs during the Country.getCountryFromNameString() call on line 88, which would cause a NullPointerException.
Suggested change
| country = Country.getCountryFromNameString(countryString); | |
| String valueYear = lastDatabaseCountryAndYear.getValue(country.toString()).toString(); | |
| startYear = Integer.parseInt(valueYear); | |
| } catch (NullPointerException e) { | |
| System.out.println("No last database country and year found."); | |
| countryString = "United Kingdom"; | |
| country = Country.getCountryFromNameString(countryString); | |
| country = Country.getCountryFromNameString(countryString); | |
| if (country == null) { | |
| country = Country.UNITED_KINGDOM; | |
| } | |
| String valueYear = lastDatabaseCountryAndYear.getValue(country.toString()).toString(); | |
| startYear = Integer.parseInt(valueYear); | |
| } catch (NullPointerException e) { | |
| System.out.println("No last database country and year found."); | |
| countryString = "United Kingdom"; | |
| country = Country.getCountryFromNameString(countryString); | |
| if (country == null) { | |
| country = Country.UNITED_KINGDOM; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
countrybefore referencing it #224 by puttingcountrysetter in right places