Windows vscode with sonarLint v3.12.0 like [Java:S2129] There's no valueOf() for new String(byte[]) reports S2129 with the following:
public String bubba() {
return new String(Base64.getEncoder().encode(getVar(EnvVar.BUBBA).getBytes()));
}
private String getVar(final EnvVar _v) { return _v.getFromEnvOrProperty(m_settings); }
If I move the EnvVar
enum into the same source part then the S2129 goes away. Same if I pass a local quoted string to the encode()
like encode("getVar(EnvVar.BUBBA)")
.
Using a local for the byte array the problem goes away:
final byte[] b = Base64.getEncoder().encode(getVar(EnvVar.BUBBA).getBytes());
return new String(b);
The EnvVar
in a separate file looks like:
public enum EnvVar {
BUBBA("bubba"),
;
private String m_name;
EnvVar(final String _name) { m_name = _name; }
@Override public String toString() { return m_name; }
public String getFromEnvOrProperty(final Settings_s) { final String fromEnv = System.getenv(m_name); return !isNullOrEmpty(fromEnv) ? fromEnv : _s.getProperty(m_name); }
}