From 2d7c1f47686e05bcae8a58d5969b24922a977360 Mon Sep 17 00:00:00 2001 From: Benjamin Attal Date: Sun, 20 Apr 2014 13:22:15 -0400 Subject: [PATCH] Fix array out of bounds exception coming from JavaParser.java --- .../main/java/com/bitshift/parsing/parsers/JavaParser.java | 13 +++++++++---- test/{java_parser_test.py => parser_test.py} | 0 2 files changed, 9 insertions(+), 4 deletions(-) rename test/{java_parser_test.py => parser_test.py} (100%) diff --git a/parsers/java/src/main/java/com/bitshift/parsing/parsers/JavaParser.java b/parsers/java/src/main/java/com/bitshift/parsing/parsers/JavaParser.java index 48287aa..0150af4 100644 --- a/parsers/java/src/main/java/com/bitshift/parsing/parsers/JavaParser.java +++ b/parsers/java/src/main/java/com/bitshift/parsing/parsers/JavaParser.java @@ -94,14 +94,19 @@ public class JavaParser extends Parser { ((QualifiedName) nameObj).getFullyQualifiedName() : ((SimpleName) nameObj).getIdentifier(); List statements = node.getBody().statements(); - Statement last = statements.get(statements.size() - 1); int sl = this.root.getLineNumber(node.getStartPosition()); int sc = this.root.getColumnNumber(node.getStartPosition()); - int el = this.root.getLineNumber(last.getStartPosition()); - int ec = this.root.getColumnNumber(last.getStartPosition()); + Integer el = null; + Integer ec = null; - data.put("coord", Symbols.createCoord(sl, sc, null, null)); + if (statements.size() > 0) { + Statement last = statements.get(statements.size() - 1); + el = this.root.getLineNumber(last.getStartPosition()); + ec = this.root.getColumnNumber(last.getStartPosition()); + } + + data.put("coord", Symbols.createCoord(sl, sc, el, ec)); data.put("name", name); this._cache.push(data); return true; diff --git a/test/java_parser_test.py b/test/parser_test.py similarity index 100% rename from test/java_parser_test.py rename to test/parser_test.py