Hi all,
SonarCloud reports “Remove this instantiation of String” warning for the following pieces of Java code:
public static String getDChars( byte[] block, int pos, int length )
{
return new String( block, pos - 1, length ).trim();
}
public static String getDChars( byte[] block, int pos, int length, String encoding )
{
try {
return new String( block, pos - 1, length, encoding ).trim();
}
catch ( UnsupportedEncodingException ex ) {
throw new RuntimeException( ex );
}
}
It’s obvious however that standard Java String
class has non-static methods, so its instantiation is absolutely legitimate.