I am using this javaparser https://github.com/javaparser/javaparser to parse a lot of java source codes of some github users to make some statistics from them (this is for a university project). Everything seems to work fine, but at some point, a particular source code produces this error:
Exception in thread "main" com.github.javaparser.TokenMgrError: Lexical error at line 6, column 2. Encountered: <EOF> after : ""
This is what is written in that file:
public class Test {
/**<caret>
public void foo() {
}
}
This is how I parse the file:
...
new NodeIterator(new NodeIterator.NodeHandler() {
@Override
public boolean handle(Node node) {
...
};
}).explore(JavaParser.parse(file));
...
This is the NodeIterator class:
public class NodeIterator {
public interface NodeHandler {
boolean handle(Node node);
}
private NodeHandler nodeHandler;
public NodeIterator(NodeHandler nodeHandler) {
this.nodeHandler = nodeHandler;
}
public void explore(Node node) {
if (nodeHandler.handle(node)) {
for (Node child : node.getChildrenNodes()) {
explore(child);
}
}
}
}
I have understood the problem, but this problem stops the entire parsing. I have a lot of files to parse inside a for, so how can I do to keep parsing the other files? Or is there a tool to check if a java file is "well written" before parsing it?