Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

Commit

Permalink
fix NullPointerException on files with no syntax nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
hegemonic committed Oct 27, 2013
1 parent 661ead6 commit 1dad8ed
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/org/jsdoc/AstBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ public NativeObject build(String sourceCode, String sourceName)

root = parser.parse(sourceCode, sourceName, 1);

// ast will be null if there are no syntax nodes
ast = processNode(root);
if (ast == null) {
ast = newObject();
}

attachRemainingComments();

return ast;
Expand Down Expand Up @@ -202,7 +207,12 @@ private Integer getSyntaxStart()
node = (AstNode)node.getNext();
}

return node.getAbsolutePosition();
if (node != null) {
return node.getAbsolutePosition();
} else {
// no syntax nodes, just comments (or an empty file)
return null;
}
}

private boolean isJsDocComment(Comment comment)
Expand Down Expand Up @@ -243,7 +253,7 @@ private void attachRemainingComments()
range = (List<Integer>)comment.get("range", comment);
start = range.get(0);

if (start < syntaxStart) {
if (syntaxStart != null && start < syntaxStart) {
leadingComments.add(comment);
} else {
trailingComments.add(comment);
Expand Down

0 comments on commit 1dad8ed

Please sign in to comment.