Bug 236230 - [formatter] SIOOBE while formatting a compilation unit.
Summary: [formatter] SIOOBE while formatting a compilation unit.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.4.1   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-09 07:07 EDT by Frederic Fusier CLA
Modified: 2008-08-28 12:14 EDT (History)
2 users (show)

See Also:


Attachments
Small test case to reproduce the problem (898 bytes, text/plain)
2008-06-09 09:11 EDT, Frederic Fusier CLA
no flags Details
Proposed patch (75.36 KB, patch)
2008-06-13 12:33 EDT, Frederic Fusier CLA
no flags Details | Diff
Updated patch (22.79 KB, patch)
2008-06-20 11:53 EDT, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Frederic Fusier CLA 2008-06-09 07:07:02 EDT
Using I20080606-0100.

On Ganymede RC3 full source workspace, a StringIndexOutOfBoundException occurs while formatting CU org/eclipse/emf/common/util/URI.Java:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.<init>(String.java:208)
at org.eclipse.jdt.internal.formatter.Scribe.printCodeSnippet(Scribe.java:1680)
at org.eclipse.jdt.internal.formatter.Scribe.printJavadocHtmlTag(Scribe.java:3092)
at org.eclipse.jdt.internal.formatter.Scribe.printJavadocHtmlTag(Scribe.java:3001)
at org.eclipse.jdt.internal.formatter.Scribe.printJavadocBlock(Scribe.java:2346)
at org.eclipse.jdt.internal.formatter.Scribe.printJavadocComment(Scribe.java:2694)
at org.eclipse.jdt.internal.formatter.Scribe.printComment(Scribe.java:1873)
at org.eclipse.jdt.internal.formatter.Scribe.printComment(Scribe.java:1769)
at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.visit(CodeFormatterVisitor.java:4107)
at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.traverse(MethodDeclaration.java:209)
at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.format(CodeFormatterVisitor.java:542)
at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.formatTypeMembers(CodeFormatterVisitor.java:2016)
at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.format(CodeFormatterVisitor.java:1170)
at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.visit(CodeFormatterVisitor.java:5179)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1198)
at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.visit(CodeFormatterVisitor.java:3056)
at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:656)
at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.format(CodeFormatterVisitor.java:799)
at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.formatCompilationUnit(DefaultCodeFormatter.java:331)
at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:203)
at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:186)
...
Comment 1 Frederic Fusier CLA 2008-06-09 07:09:33 EDT
The problem exists since 3.4M7 when the new comment formatter has been activated.
The javadoc text end is not properly initialized in the commentParse() method of AbstracCommentParser...
Comment 2 Frederic Fusier CLA 2008-06-09 09:11:13 EDT
Created attachment 104144 [details]
Small test case to reproduce the problem
Comment 3 Frederic Fusier CLA 2008-06-09 09:33:32 EDT
Do you have a similar configuration than bug 199392 (i.e. a project which name ends with '.jar')?

Would it be possible that you give it a try with 3.4RC3 on your workspace and let me know if you still get the problem?

Thanks in advance
Comment 4 Frederic Fusier CLA 2008-06-09 09:35:31 EDT
(In reply to comment #3)
Ooops wrong bug, forget this comment...
Comment 5 Frederic Fusier CLA 2008-06-13 12:33:50 EDT
Created attachment 104887 [details]
Proposed patch

The StringIndexOutOfBoundException was initially due to the fact that the javadocTextEnd field was not properly reset at the beginning of commentParse() method in AbstractCommentParser.

However, only fixing this was not really appropriate as it exhibits the real origin of the problem: the text end position was sometimes incorrect while pushing the text...

So, in this patch, the position of the end of text has been reviewed and fixed everywhere it's used... Note that although the change is made in the root of hierarchy of comment parsers it does only affect text position/length and does not represent a too risky change.
Comment 6 Frederic Fusier CLA 2008-06-20 11:53:06 EDT
Created attachment 105505 [details]
Updated patch

Same patch than previous one but without unrelated test classes changes...
Comment 7 Frederic Fusier CLA 2008-06-20 11:55:34 EDT
Released for 3.5M1 in HEAD stream.
Comment 8 Jerome Lanneluc CLA 2008-06-25 01:59:28 EDT
+1 to backport to 3.4.1
Comment 9 Frederic Fusier CLA 2008-06-25 05:04:02 EDT
Released for 3.4.1
Comment 10 Olivier Thomann CLA 2008-08-06 12:23:54 EDT
Verified for 3.5M1 using I20080805-1307
Comment 11 Olivier Thomann CLA 2008-08-06 13:16:02 EDT
Reopen to close as RESOLVED/FIXED. Will be closed as VERIFIED during 3.4.1
verification pass.
Comment 12 Olivier Thomann CLA 2008-08-06 13:26:03 EDT
Fixed.
Comment 13 Olivier Thomann CLA 2008-08-28 12:14:45 EDT
Verified for 3.4.1 using M20080827-2000