Skip to content
Snippets Groups Projects
Commit 3057b83b authored by Florian Angerer's avatar Florian Angerer
Browse files

Fix copyrights and NPE.

parent d72671c4
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.r.test.packages.analyzer;
import java.io.IOException;
......@@ -12,7 +34,7 @@ public class FileLineListReader extends FileLineReader {
public FileLineListReader(List<String> lines) {
Iterator<String> iterator = lines.iterator();
this.it = iterator;
this.empty = iterator.hasNext();
this.empty = !iterator.hasNext();
}
@Override
......
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.r.test.packages.analyzer;
import java.io.IOException;
import java.util.Iterator;
import java.util.NoSuchElementException;
public abstract class FileLineReader implements Iterable<String> {
......@@ -10,33 +30,4 @@ public abstract class FileLineReader implements Iterable<String> {
public abstract boolean isEmpty();
@Override
public Iterator<String> iterator() {
return new Iterator<String>() {
private String line = null;
@Override
public boolean hasNext() {
try {
if (line == null) {
line = readLine();
}
return line != null;
} catch (IOException e) {
// ignore
}
return false;
}
@Override
public String next() {
if (hasNext()) {
return line;
}
throw new NoSuchElementException();
}
};
}
}
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.r.test.packages.analyzer;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class FileLineStreamReader extends FileLineReader {
/** Maximum number of lines that will be analyzed. */
......@@ -9,25 +33,60 @@ public class FileLineStreamReader extends FileLineReader {
private final BufferedReader reader;
private int cnt = 0;
private String lookahead = null;
private boolean empty;
public FileLineStreamReader(BufferedReader in) {
this.reader = in;
empty = true;
try {
nextLine();
empty = lookahead == null;
} catch (IOException e) {
// ignore
}
}
@Override
public String readLine() throws IOException {
private String nextLine() throws IOException {
if (cnt++ >= MAX_LINES) {
throw new IOException("File is too large for analysis.");
}
return reader.readLine();
String line = lookahead;
lookahead = reader.readLine();
return line;
}
@Override
public String readLine() throws IOException {
return nextLine();
}
@Override
public boolean isEmpty() {
try {
return reader.ready();
} catch (IOException e) {
return false;
}
return empty;
}
@Override
public Iterator<String> iterator() {
return new Iterator<String>() {
@Override
public boolean hasNext() {
return lookahead != null;
}
@Override
public String next() {
if (hasNext()) {
try {
return nextLine();
} catch (IOException e) {
}
}
throw new NoSuchElementException();
}
};
}
}
......@@ -189,13 +189,13 @@ public class LogFileParser {
// cases)
Optional<Path> findFirst = null;
findFirst = Files.find(logFile.path.getParent(), 3, (path, attr) -> path.getFileName().equals(outputFile.getFileName())).findFirst();
try (BufferedReader in = Files.newBufferedReader(findFirst.get())) {
if (findFirst.isPresent()) {
if (findFirst.isPresent()) {
try (BufferedReader in = Files.newBufferedReader(findFirst.get())) {
ignoreFiles.add(findFirst.get());
checkResults.problems.addAll(applyDetectors(Token.OUTPUT_MISMATCH_FASTR, findFirst.get(), 0, new FileLineStreamReader(in)));
} catch (IOException e) {
// silently ignore
}
} catch (IOException e) {
// silently ignore
}
if (findFirst == null || !findFirst.isPresent()) {
LOGGER.warning("Cannot read output file " + outputFile);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment