G
Guest
Gast
Hallo,
ich hatte diese Methode um eine CSV-Datei einzulesen:
Den Java Code hab ich unter Eclipse mit dem FindBug Plugin prüfen lassen und so geändert:
Nun findet FindBug in der Zeile 18
den Fehler/Hinweis:
Gruß & vielen Dank für Eure Hilfe
ich hatte diese Methode um eine CSV-Datei einzulesen:
Code:
private void readCSVFile() throws IOException, ParseException {
String lineInFile = new String();
String[] fieldsPerLine = null;
try {
inputFile = new BufferedReader(new FileReader(csvFileName));
readfile: // <<== a labeled statement
while ( (lineInFile = inputFile.readLine()) != null ) {
cntLines++;
lineInFile = lineInFile.trim();
// leere Zeilen nicht beachten
if ( lineInFile.equals("") ) {
continue readfile;
}
// Kommentarzeilen nicht beachten
test4comment: // <<== a labeled statement
for ( int i = 0; i < POSSIBLE_COMMENT_CHAR.length; i++ ) {
if ( lineInFile.startsWith(POSSIBLE_COMMENT_CHAR[i]) ) {
continue readfile;
}
}
// Zeileninhalt als String Array aufnehmen
fieldsPerLine = lineInFile.split(String.valueOf(delimiter));
// prüfen ob der Eintrag aufgenommen wurde
if ( ! allItemsInFile.add(fieldsPerLine) ) {
throw new RuntimeException(" Aufnahme des Eintrages [ " +
Arrays.toString(fieldsPerLine) + " ] in Zeile [" +
cntLines + "] war nicht mgl.");
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if ( inputFile != null ) {
inputFile.close();
}
}
}
Code:
private void readCSVFile() throws IOException, ParseException {
String[] fieldsPerLine = null;
try {
inputFile = new BufferedReader(new FileReader(csvFileName));
readfile: // <<== this is a labeled statement
for ( cntLines = 1 ; true; cntLines++ ) {
String lineInFile = inputFile.readLine();
if ( lineInFile != null ) {
lineInFile = lineInFile.trim();
// leere Zeilen nicht beachten
if ( lineInFile.equals("") ) {
continue readfile;
}
}
// Kommentarzeilen nicht beachten
checkcomment: // <<== this is a labeled statement
for ( int i = 0; i < POSSIBLE_COMMENT_CHAR.length; i++ ) {
if ( lineInFile.startsWith(POSSIBLE_COMMENT_CHAR[i]) ) {
continue readfile; // hier die aeussere for-Schleife beendet
}
}
// Zeileninhalt als String Array aufnehmen
fieldsPerLine = lineInFile.split(String.valueOf(delimiter));
// prüfen ob der Eintrag aufgenommen wurde
if ( ! allItemsInFile.add(fieldsPerLine) ) {
throw new RuntimeException(" Aufnahme des Eintrages [ " +
Arrays.toString(fieldsPerLine) + " ] in Zeile [" +
cntLines + "] war nicht mgl.");
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if ( inputFile != null ) {
inputFile.close();
}
}
}
Code:
if ( lineInFile.startsWith(POSSIBLE_COMMENT_CHAR[i]) ) {
Ich prüf' doch schon in der Zeile 8 ob die Variable lineInFile möglicherweise null sein könnte. Macht hier eine nochmalige Prüfung noch einen Sinn ???:L Leider hab ich aktuell keine Idee was ich hier machen könnte, damit FindBug zufrieden ist.<NP> Null value is guaranteed to be dereferenced <NP_GUARANTEED_DEREF>
There is a statement or branch that if executed guarantees that a value is null at this point, and that value that is guaranteed to be dereferenced (except on forward paths involving runtime exceptions).
Gruß & vielen Dank für Eure Hilfe