Sonar complains that the Scanner should always be closed, is it right?
Scanner scanner = new Scanner("simple string")
This scanner is not scanning from file etc. Why should it be closed?
By calling new Scanner("string") it creates a StringReader which creates a character stream. So you have to close it.
See the OpenJDK source code
public Scanner(String source) {
this(new StringReader(source), WHITESPACE_PATTERN);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With