Expand my Community achievements bar.

SOLVED

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

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

try like this:

 

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

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

try like this:

 

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