org.sonar.l10n.java.rules.squid.S2677.html Maven / Gradle / Ivy
The newest version!
When a method is called that returns data read from some data source, that data should be stored rather than thrown away. Any other course of action is surely a bug.
This rule raises an issue when the return value of any of the following is ignored or merely null-checked: Reader.read()
, BufferedReader.readLine()
, and these methods in any child classes.
Noncompliant Code Example
public void doSomethingWithFile(String fileName) {
BufferedReader buffReader = null;
try {
buffReader = new BufferedReader(new FileReader(fileName));
while (buffReader.readLine() != null) { // Noncompliant
// ...
}
} catch (IOException e) {
// ...
}
}
Compliant Solution
public void doSomethingWithFile(String fileName) {
BufferedReader buffReader = null;
try {
buffReader = new BufferedReader(new FileReader(fileName));
String line = null;
while ((line = buffReader.readLine()) != null) {
// ...
}
} catch (IOException e) {
// ...
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy