Skip to content

Commit b144678

Browse files
authored
Merge pull request #1216 from smartdevicelink/bugfix/issue_1215
Fix potential NPEs in BaseMenuManager
2 parents 77c7bda + ff9ef60 commit b144678

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuManagerTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,27 @@ public void testAlgorithmTest5(){
425425
assertEquals(menuManager.keepsOld.size(), 3);
426426
}
427427

428+
public void testSettingNullMenu(){
429+
430+
// Make sure we can send an empty menu with no issues
431+
// start fresh
432+
menuManager.oldMenuCells = null;
433+
menuManager.menuCells = null;
434+
menuManager.inProgressUpdate = null;
435+
menuManager.waitingUpdateMenuCells = null;
436+
menuManager.waitingOnHMIUpdate = false;
437+
438+
menuManager.currentHMILevel = HMILevel.HMI_FULL;
439+
// send new cells. They should set the old way
440+
List<MenuCell> oldMenu = createDynamicMenu1();
441+
List<MenuCell> newMenu = null;
442+
menuManager.setMenuCells(oldMenu);
443+
assertEquals(menuManager.menuCells.size(), 4);
444+
445+
menuManager.setMenuCells(newMenu);
446+
assertEquals(menuManager.menuCells.size(), 0);
447+
}
448+
428449
public void testClearingMenu(){
429450

430451
// Make sure we can send an empty menu with no issues

base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ public void setMenuCells(@NonNull List<MenuCell> cells){
175175
if (currentHMILevel == null || currentHMILevel.equals(HMILevel.HMI_NONE) || currentSystemContext.equals(SystemContext.SYSCTXT_MENU)){
176176
// We are in NONE or the menu is in use, bail out of here
177177
waitingOnHMIUpdate = true;
178-
waitingUpdateMenuCells = new ArrayList<>(clonedCells);
178+
waitingUpdateMenuCells = new ArrayList<>();
179+
if (clonedCells != null && !clonedCells.isEmpty()) {
180+
waitingUpdateMenuCells.addAll(clonedCells);
181+
}
179182
return;
180183
}
181184
waitingOnHMIUpdate = false;
@@ -186,7 +189,10 @@ public void setMenuCells(@NonNull List<MenuCell> cells){
186189
oldMenuCells = new ArrayList<>(menuCells);
187190
}
188191
// copy new list
189-
menuCells = new ArrayList<>(clonedCells);
192+
menuCells = new ArrayList<>();
193+
if (clonedCells != null && !clonedCells.isEmpty()) {
194+
menuCells.addAll(clonedCells);
195+
}
190196

191197
// HashSet order doesnt matter / does not allow duplicates
192198
HashSet<String> titleCheckSet = new HashSet<>();

0 commit comments

Comments
 (0)