Leiste mit Community-Erfolgen erweitern.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
GELÖST

Return a copy of "customItems". - Vulnerability - Minor

Avatar

Level 2

For the below code getting Vulnerability, can someone assist with what to write instead:

@Override

    public List<OptionItem> getCustomItems() {

        return customItems;

    }

 

Passing this

  @Override
  public List<OptionItem> getCustomItems() {
    return List.copyOf(customItems);
  }

  @Override
  public List<OptionItem> getCustomItems() {
    return customItems != null ? List.copyOf(customItems) : List.of();
  }

 

getting null pointer exception

Themen

Anhand von Themen werden Community-Inhalte kategorisiert und Sie können so relevanten Inhalt besser finden.

1 Akzeptierte Lösung

Avatar

Korrekte Antwort von
Community Advisor

try like this:

 

@Override
public List<OptionItem> getCustomItems() {
return customItems != null ? new ArrayList<>(customItems) : new ArrayList<>();
}

Lösung in ursprünglichem Beitrag anzeigen

1 Antwort

Avatar

Korrekte Antwort von
Community Advisor

try like this:

 

@Override
public List<OptionItem> getCustomItems() {
return customItems != null ? new ArrayList<>(customItems) : new ArrayList<>();
}