2023년 5월 18일 목요일

자바 시큐어코딩 Public메소드부터 반환된 Private 배열 또는 private 배열에 Public 데이타 할당

Private 배열에  public 데이타할당
또는
Public 메소드부터 반환된 private배열

예제

public class ListDTO{
    private List<testDto> testList;
    public List<testDto> getTestList(){
        return testList;
    }
}

>>> 변경
public class ListDTO{
    private List<testDto> testList;
    public List<testDto> getTestList(){
        List<testDto> aa = null;
        if (this.testList != null ){
            aa = this.testList.stream().collect(Collectors.toList());
        }
        return aa;
    }
}

단순  배열인 경우 clone 만 사용하여 변환하면됨

private String[] arrCol = {};
public void setTestName(String[] col} thows IllegalArgumentException{
    String[] cloneArr = {};
    if (col != null ){
        cloneArr = col.clone();
    }
    this.arrCol = cloneArr;
}

댓글 없음:

댓글 쓰기