Fix NullPointerException in TestPanel Prefs.getRecentMessageXmlFiles on fresh install#143
Open
jmwall wants to merge 1 commit intohapifhir:masterfrom
Open
Conversation
…nstall myRecentMessageXmlFiles is null when no prefs.xml exists yet, causing an NPE when getRecentMessageXmlFiles() iterates over it. Added null check matching the existing pattern used for myOpenTableFiles. Regression from c679d04 (Sep 2012) which migrated Prefs from the Java Preferences API to JAXB-serialized XML fields without guarding this field against null.
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.
Bug
On a fresh install (no existing
prefs.xml), closing or removing a message from the TestPanel message list throws aNullPointerExceptionatPrefs.java:388becausemyRecentMessageXmlFilesisnullwhengetRecentMessageXmlFiles()iterates over it.Fix
Added a null check that initializes
savedValsto an emptyArrayList<XmlFormat>()ifmyRecentMessageXmlFilesis null — matching the existing pattern already used formyOpenTableFilesin the same class.Reproduction
~/HapiTestPanel/prefs.xml(or launch on a machine that has never run TestPanel)Root Cause
Regression introduced in
[c679d04](https://github.com/hapifhir/hapi-hl7v2/commit/c679d04c08e0d46c4d1036dd2408d80ac77a2347)("Allow exporting and importing of profile group files", Sep 2012) which refactoredPrefs.javafrom the Java Preferences API to JAXB-serialized XML fields.The old code always produced a non-null list because
ourPrefs.get()provided a default empty string:The new code directly assigns the JAXB field, which is
nulluntilprefs.xmlexists and has been deserialized:Notably, the same commit correctly handled the null case for the analogous
myOpenTableFilesfield:This fix applies the same null-guard pattern that was used for
myOpenTableFilesbut was missed formyRecentMessageXmlFiles.