Community
Participate
Working Groups
JDT does not consider the following statement as an error: String[] s = {"",};
Also note: String[] s = {"",,,}; causes IAE: !ENTRY org.eclipse.jdt.ui 4 2 2006-02-02 08:57:30.126 !MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jdt.ui". !STACK 0 java.lang.IllegalArgumentException at org.eclipse.jdt.core.dom.ASTNode.setSourceRange(ASTNode.java:2599) at org.eclipse.jdt.core.dom.ASTConverter.convertToVariableDeclarationStatement(ASTConverter.java:2997) at org.eclipse.jdt.core.dom.ASTConverter.checkAndAddMultipleLocalDeclaration(ASTConverter.java:399) at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:512) at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:182) at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2636) at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1238) at org.eclipse.jdt.core.dom.AST.convertCompilationUnit(AST.java:270) at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.makeConsistent(ReconcileWorkingCopyOperation.java:160) at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:71) at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:720) at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:779) at org.eclipse.jdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1120) at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy$1.run(JavaReconcilingStrategy.java:97) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37) at org.eclipse.core.runtime.Platform.run(Platform.java:804) at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:82) at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.initialReconcile(JavaReconcilingStrategy.java:175) at org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.initialReconcile(CompositeReconcilingStrategy.java:114) at org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.initialReconcile(JavaCompositeReconcilingStrategy.java:120) at org.eclipse.jface.text.reconciler.MonoReconciler.initialProcess(MonoReconciler.java:103) at org.eclipse.jdt.internal.ui.text.JavaReconciler.initialProcess(JavaReconciler.java:328) at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(AbstractReconciler.java:170)
(In reply to comment #0) > JDT does not consider the following statement as an error: > > String[] s = {"",}; It *is* no error - arrays may have a trailing comma after the last element.
Adapted summary.
> It *is* no error - arrays may have a trailing comma after the last element. Then javac has error :)
What makes you say that javac is wrong? I could compile the following code with javac 1.4.2, 1.3.1 and 1.5.0. public class X { public static void main(String[] args) { String[] s = {"",}; System.out.println(s.length); } }
(In reply to comment #1) > Also note: > String[] s = {"",,,}; > causes IAE: > !ENTRY org.eclipse.jdt.ui 4 2 2006-02-02 08:57:30.126 > !MESSAGE Problems occurred when invoking code from plug-in: > "org.eclipse.jdt.ui". > !STACK 0 > java.lang.IllegalArgumentException > at org.eclipse.jdt.core.dom.ASTNode.setSourceRange(ASTNode.java:2599) > at > org.eclipse.jdt.core.dom.ASTConverter.convertToVariableDeclarationStatement(ASTConverter.java:2997) > at Daniel, What version did you use? I cannot reproduce this failure. I am getting a syntax error.
Daniel, Don't worry. I reproduced it. I needed to enable statement recovery.
The problem comes from the local variable that has no declaration source end set. The declaration end is set to the end of the name, but the declaration source end is not set. David, I will investigate. If I cannot figure out where the bug is, I'll reassign it to you.
David, The problem is inside the statement recovery. Once the method's statements are recovered, the local declaration has no declaration source end.
(In reply to comment #5) > What makes you say that javac is wrong? > I could compile the following code with javac 1.4.2, 1.3.1 and 1.5.0. > > public class X { > > public static void main(String[] args) { > String[] s = {"",}; > System.out.println(s.length); > } > } > Sorry, this was my mistake with a wrong code. Why a trailing space has no problem? What is the effect?
*** Bug 126309 has been marked as a duplicate of this bug. ***
(In reply to comment #10) > Sorry, this was my mistake with a wrong code. > Why a trailing space has no problem? What is the effect? A trailing comma has no meaning. It is spec'd that way. Don't ask us why? <g>
Fixed and test added ASTConverterRecoveryTest#test0005 The problems are 1) the end of statements are not computed at the end of recovery if missing 2) to much Expression nodes are recovered if the statements recovery can't be complete 3) the mapping non-terminals -> terminals is missing for ArrayInitializer. So the statement recovery isn't completed I fix these three problems
Verified for 3.2 M5 using build I20060215-0010.