Sonar Violation: Security - Array is stored directly

后端 未结 7 2169
广开言路
广开言路 2020-11-27 04:53

There is a Sonar Violation:

Sonar Violation: Security - Array is stored directly

public void setMyArray(String[] myArray) { 
  this.         


        
7条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 05:37

    I had the same issue:

    Security - Array is stored directly The user-supplied array 'palomitas' is stored directly.

    my original method:

    public void setCheck(boolean[] palomitas) {
            this.check=palomitas;
        }
    

    fixed turned to:

    public void setCheck(boolean[] palomitas) { 
          if(palomitas == null) { 
            this.check = new boolean[0]; 
          } else { 
           this.check = Arrays.copyOf(palomitas, palomitas.length); 
          } 
    }
    

    Other Example:

    Security - Array is stored directly The user-supplied array

    private String[] arrString;
    
        public ListaJorgeAdapter(String[] stringArg) {      
            arrString = stringArg;
        }
    

    Fixed:

    public ListaJorgeAdapter(String[] stringArg) {  
        if(stringArg == null) { 
          this.arrString = new String[0]; 
        } else { 
          this.arrString = Arrays.copyOf(stringArg, stringArg.length); 
        } 
    }
    

提交回复
热议问题