Bug 126148 - IAE when typing String[] s = {"",,,};
Summary: IAE when typing String[] s = {"",,,};
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M5   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 126309 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-02-02 02:49 EST by Mohsen Saboorian CLA
Modified: 2006-02-15 10:28 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mohsen Saboorian CLA 2006-02-02 02:49:54 EST
JDT does not consider the following statement as an error:

String[] s =  {"",};
Comment 1 Dani Megert CLA 2006-02-02 02:59:39 EST
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)

Comment 2 Tom Hofmann CLA 2006-02-02 03:27:00 EST
(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.
Comment 3 Dani Megert CLA 2006-02-02 03:42:57 EST
Adapted summary.
Comment 4 Mohsen Saboorian CLA 2006-02-02 04:46:48 EST
> It *is* no error - arrays may have a trailing comma after the last element.
Then javac has error :)

Comment 5 Olivier Thomann CLA 2006-02-02 12:11:53 EST
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);
    }
}
Comment 6 Olivier Thomann CLA 2006-02-02 15:04:02 EST
(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.
Comment 7 Olivier Thomann CLA 2006-02-02 16:01:23 EST
Daniel,

Don't worry. I reproduced it.
I needed to enable statement recovery.
Comment 8 Olivier Thomann CLA 2006-02-02 16:06:17 EST
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.
Comment 9 Olivier Thomann CLA 2006-02-02 16:46:44 EST
David,

The problem is inside the statement recovery. Once the method's statements are recovered, the local declaration has no declaration source end.
Comment 10 Mohsen Saboorian CLA 2006-02-03 00:37:33 EST
(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?
Comment 11 Dani Megert CLA 2006-02-03 05:08:52 EST
*** Bug 126309 has been marked as a duplicate of this bug. ***
Comment 12 Olivier Thomann CLA 2006-02-03 09:08:56 EST
(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>
Comment 13 David Audel CLA 2006-02-06 09:12:43 EST
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
Comment 14 Frederic Fusier CLA 2006-02-15 10:28:43 EST
Verified for 3.2 M5 using build I20060215-0010.