Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 280061 - [formatter] AIOOBE while formatting javadoc comment
Summary: [formatter] AIOOBE while formatting javadoc comment
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.5.1   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-06-12 07:05 EDT by Frederic Fusier CLA
Modified: 2009-08-27 15:18 EDT (History)
3 users (show)

See Also:


Attachments
Proposed patch (5.98 KB, patch)
2009-06-17 10:44 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 2009-06-12 07:05:17 EDT
Using build

Consider the following source:

public interface Z {
/**
 * <pre>
 *   void solve(Executor e,
 *              Collection&lt;Callable&lt;Result&gt;&gt; solvers)
 *     throws InterruptedException, ExecutionException {
 *       CompletionService&lt;Result&gt; ecs
 *           = new ExecutorCompletionService&lt;Result&gt;(e);
 *       for (Callable&lt;Result&gt; s : solvers)
 *           ecs.submit(s);
 *       int n = solvers.size();
 *       for (int i = 0; i &lt; n; ++i) {
 *           Result r = ecs.take().get();
 *           if (r != null)
 *               use(r);
 *       }
 *   }
 * </pre>
 */
 void foo();
}

Format it using an Eclipse built-in profile...
Boom, an AIOOBE occurs:

java.lang.ArrayIndexOutOfBoundsException: 463
	at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.visit(CodeFormatterVisitor.java:4117)
	at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.traverse(MethodDeclaration.java:207)
	at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.format(CodeFormatterVisitor.java:542)
	at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.formatClassBodyDeclarations(CodeFormatterVisitor.java:1528)
	at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.format(CodeFormatterVisitor.java:772)
	at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.internalFormatClassBodyDeclarations(DefaultCodeFormatter.java:452)
	at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.probeFormatting(DefaultCodeFormatter.java:545)
	at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:212)
	at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:188)
	at org.eclipse.jdt.internal.formatter.comment.CommentFormatterUtil.format2(CommentFormatterUtil.java:71)
	at org.eclipse.jdt.internal.formatter.Scribe.printCodeSnippet(Scribe.java:1861)
	at org.eclipse.jdt.internal.formatter.Scribe.printJavadocHtmlTag(Scribe.java:3279)
	at org.eclipse.jdt.internal.formatter.Scribe.printJavadocBlock(Scribe.java:2533)
	at org.eclipse.jdt.internal.formatter.Scribe.printJavadocComment(Scribe.java:2881)
	at org.eclipse.jdt.internal.formatter.Scribe.printComment(Scribe.java:2015)
	at org.eclipse.jdt.internal.formatter.Scribe.printComment(Scribe.java:1911)
	at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.visit(CodeFormatterVisitor.java:4135)
	at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.traverse(MethodDeclaration.java:207)
	at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.format(CodeFormatterVisitor.java:542)
	at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.formatTypeMembers(CodeFormatterVisitor.java:2036)
	at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.format(CodeFormatterVisitor.java:1190)
	at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.visit(CodeFormatterVisitor.java:5207)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1220)
	at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.visit(CodeFormatterVisitor.java:3084)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:645)
	at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.format(CodeFormatterVisitor.java:805)
	at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.formatCompilationUnit(DefaultCodeFormatter.java:333)
	at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:205)
	at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:188)
	at org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.reformat(CodeFormatterUtil.java:288)
	at org.eclipse.jdt.internal.ui.text.java.JavaFormattingStrategy.format(JavaFormattingStrategy.java:65)
Comment 1 Frederic Fusier CLA 2009-06-12 07:18:02 EDT
This bug has been revealed by the fix for bug 270148.

Before it, the probeFormatting method of DefaultCodeFormatter always failed to identify any valid source to format as it was 1.5 code parsed with 1.4 compliance...

After the fix, the parser returns a recovered class body declaration, hence spot this problem in the CodeFormatterVisitor.

I'm currently investigating if this is a new or always existing issue...
Comment 2 Frederic Fusier CLA 2009-06-12 08:48:51 EDT
(In reply to comment #0)
> Using build
> 
... I20090609-1400
Comment 3 Frederic Fusier CLA 2009-06-12 08:57:12 EDT
It seems to be there since fix for bug 128848.

Following test case is formatted correctly without any exception:
public class X {

	/**
	 * <pre>
	 * public class Try {
	 *     void m() {
	 *         // test
	 *     } //end
	 * }
	 *</pre>
	 */
}
Comment 4 Frederic Fusier CLA 2009-06-17 10:44:47 EDT
Created attachment 139435 [details]
Proposed patch

When the syntax error leads to ignore further investigation in the method declaration, then verify that the scanner is not at end before testing the character at the current position...
Comment 5 Frederic Fusier CLA 2009-06-17 11:29:10 EDT
Olivier, 
As fix for bug 270148 is in 3.5.0 and exposed the formatter to encounter this exception, I think it would be safe to target this bug for 3.5.1. Do you agree?
Comment 6 Olivier Thomann CLA 2009-06-17 13:47:17 EDT
yes, +1 for 3.5.1.
Any failure during formatting (exception thrown and/or code lost or added) should investigated for 3.5.1.
Only minor formatting issues can be skipped for 3.5.1 and be investigated for 3.6 only. 
Comment 7 Frederic Fusier CLA 2009-06-18 05:23:34 EDT
Released for 3.5M6 in HEAD stream.
Comment 8 Frederic Fusier CLA 2009-06-18 05:33:03 EDT
Released for 3.5.1 in R3_5_maintenance stream.
Comment 9 Srikanth Sankaran CLA 2009-08-04 00:16:58 EDT
Verified for 3.6M1 using build I20090802-2000
Comment 10 Satyam Kandula CLA 2009-08-27 09:15:10 EDT
Verified for 3.5.1 using build M20090826-1100
Comment 11 Olivier Thomann CLA 2009-08-27 15:18:42 EDT
Verified.