Community
Participate
Working Groups
Using build Consider the following source: public interface Z { /** * <pre> * void solve(Executor e, * Collection<Callable<Result>> solvers) * throws InterruptedException, ExecutionException { * CompletionService<Result> ecs * = new ExecutorCompletionService<Result>(e); * for (Callable<Result> s : solvers) * ecs.submit(s); * int n = solvers.size(); * for (int i = 0; i < 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)
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...
(In reply to comment #0) > Using build > ... I20090609-1400
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> */ }
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...
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?
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.
Released for 3.5M6 in HEAD stream.
Released for 3.5.1 in R3_5_maintenance stream.
Verified for 3.6M1 using build I20090802-2000
Verified for 3.5.1 using build M20090826-1100
Verified.