Bug 158039 - [ast rewrite] ArrayIndexOutOfBoundsException when rewriting
Summary: [ast rewrite] ArrayIndexOutOfBoundsException when rewriting
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M6   Edit
Assignee: Martin Aeschlimann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-20 14:19 EDT by Daniel Stephan CLA
Modified: 2007-03-21 05:37 EDT (History)
1 user (show)

See Also:


Attachments
AST Parser test (8.03 KB, text/plain)
2007-01-08 02:37 EST, Gireesh Kumar CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Stephan CLA 2006-09-20 14:19:42 EDT
Hi,

first let me show you the stacktrace:
     [java] Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
     [java]     at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.getIndentOfLine(ASTRewriteAnalyzer.java:228)
     [java]     at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.getIndent(ASTRewriteAnalyzer.java:1016)
     [java]     at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.rewriteRequiredNode(ASTRewriteAnalyzer.java:582)
     [java]     at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.visit(ASTRewriteAnalyzer.java:2443)
     [java]     at org.eclipse.jdt.core.dom.SingleVariableDeclaration.accept0(SingleVariableDeclaration.java:364)
     [java]     at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2466)
     [java]     at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.voidVisit(ASTRewriteAnalyzer.java:314)
     [java]     at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.voidVisit(ASTRewriteAnalyzer.java:320)
     [java]     at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.doVisitUnchangedChildren(ASTRewriteAnalyzer.java:335)
     [java]     at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.visit(ASTRewriteAnalyzer.java:1812)
     [java]     at org.eclipse.jdt.core.dom.CatchClause.accept0(CatchClause.java:160)
     [java]     at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2466)
     [java]     at org.eclipse.jdt.core.dom.rewrite.ASTRewrite.internalRewriteAST(ASTRewrite.java:255)
     [java]     at org.eclipse.jdt.core.dom.rewrite.ASTRewrite.rewriteAST(ASTRewrite.java:188)
     [java]     at ***.VisitorHandler.handle(VisitorHandler.java:183)

I looked quickly at the code and got the impression that ListLineTracker.getLineOffset(line) returns -1 and so the method breaks. It might be investigated, why it returns -1 at all... I have a hard time reproducing the problem, as it only occurs on the production system, but not in my test environment.

For know I hope that you see something in the code which could explain that -1 at this point.

As soon as I find a way to reproduce the problem, I add the info here.

Thanks,
Daniel
Comment 1 Gireesh Kumar CLA 2007-01-08 02:37:32 EST
Created attachment 56535 [details]
AST Parser test

Use this file to reproduce the issue.
Comment 2 Eric Inman CLA 2007-02-02 18:32:48 EST
I encountered this problem and it turned out to be caused by the fact that the Document I created for the rewrite was empty when I should have initialized it with the contents of the compilation unit from before the changes were made to the ASTNode's.

Obviously, the deeply nested ArrayIndexOutOfBoundsException is not the best way to report that programming error.
Comment 3 Martin Aeschlimann CLA 2007-02-12 11:48:49 EST
fixed > 20070212
Comment 4 Eric Jodet CLA 2007-03-21 05:30:49 EDT
Verified for 3.3 M6 using build I20070320-0010