I have this method:
private String generateDocumentKey(String year, Long version) {
StringBuilder idKey = new StringBuilder("");
if (Objects.nonNull(version)) {
idKey.append(year);
idKey.append(VERSION);
}
return idKey.toString();
}
but SonarQube reports this error:
Method XXX(String, String, Long) passes constant String of length 1 to character overridden method
in the line
idKey.append(VERSION);
That means the constant VERSION
is currently 1 character long and its type could be changed to char
instead to be more efficient.
It doesn't make sense in the long term (version number will get longer in the future releases), but SonarQube is just a dumb tool and you always have to judge its suggestions by yourself.