Bug 47396 - JAVA AST Creation failure
Summary: JAVA AST Creation failure
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.0 M7   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 47326 48195 50849 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-11-25 05:05 EST by Nikolay Metchev CLA
Modified: 2004-02-11 11:08 EST (History)
2 users (show)

See Also:


Attachments
The source code that caused the ast creation error (5.74 KB, text/plain)
2004-01-28 11:04 EST, shmuel siegel CLA
no flags Details
Reproducable test case (5.66 KB, text/plain)
2004-01-29 11:55 EST, Olivier Thomann CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nikolay Metchev CLA 2003-11-25 05:05:40 EST
the following text:
-----------------------------------------
//
// Created      : 25-Nov-2003, 10:00:37
// Description  : 
// Author       : Nikolay
// Copyright    : (c) Teamphone.com Ltd. 2003 - All Rights Reserved
//

/**
 * @author Nikolay
 */
public class A
{
   public A()
   {
      
   }

}
interface B
{
   public method(final int parameter);
}
----------------------------------------------------------
causes a whole series of (if autobuild is on):
-----------------------------------------------------------
java.lang.IllegalArgumentException
	at org.eclipse.jdt.core.dom.ASTNode.setSourceRange(ASTNode.java:1486)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:701)
	at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations
(ASTConverter.java:244)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:183)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:81)
	at org.eclipse.jdt.core.dom.AST.parseCompilationUnit(AST.java:354)
	at org.eclipse.jdt.core.dom.AST.parseCompilationUnit(AST.java:247)
	at 
org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartList
enerGroup.computeAST(SelectionListenerWithASTManager.java:106)
	at 
org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartList
enerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:116)
	at 
org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$1.run
(SelectionListenerWithASTManager.java:92)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:62)
------------------------------------------------------------------------
Comment 1 Nikolay Metchev CLA 2003-11-25 05:06:40 EST
M5
Comment 2 Olivier Thomann CLA 2003-11-25 08:57:34 EST
I will investigate.
Comment 3 Olivier Thomann CLA 2003-11-25 09:17:11 EST
Reproduced.
Comment 4 Olivier Thomann CLA 2003-11-25 09:22:39 EST
The problem comes from the fact that the interface's method has no return type.
Comment 5 Olivier Thomann CLA 2003-11-25 09:59:27 EST
Fixed and released in HEAD.
Regression test added.
In case of an invalid constructor, the body end and the declaration source end
were not set when the invalid constructor had no body. The fixed needs to be
done in the parser.
Comment 6 Olivier Thomann CLA 2003-11-26 08:38:49 EST
*** Bug 47326 has been marked as a duplicate of this bug. ***
Comment 7 Olivier Thomann CLA 2003-12-07 11:58:30 EST
*** Bug 48195 has been marked as a duplicate of this bug. ***
Comment 8 David Audel CLA 2003-12-17 07:05:09 EST
I can not reproduce the IllegalArgumentException in build 20031216

Verified for 3.0M6
Comment 9 shmuel siegel CLA 2004-01-28 10:11:17 EST
Using integration build 200401271238 on win2k sp4 jdk 1.4.2_01 If I start typing
private Key key;
between the java doc for a method and the method body I get a popup saying
Error: Java Ast Creation etc. when I reach the "v". Typing the same information
before the java doc does not give the error.

here is a typical log entry

java.lang.IllegalArgumentException
at org.eclipse.jdt.core.dom.ASTNode.checkNewChild(ASTNode.java:1101)
at org.eclipse.jdt.core.dom.ASTNode.replaceChild(ASTNode.java:1055)
at org.eclipse.jdt.core.dom.BodyDeclaration.setJavadoc(BodyDeclaration.java:87)
at
org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:339)
at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:268)
at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:156)
at org.eclipse.jdt.core.dom.AST.parseCompilationUnit(AST.java:932)
at
org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.computeAST(SelectionListenerWithASTManager.java:125)
at
org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:144)
at
org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$1.run(SelectionListenerWithASTManager.java:99)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:62)
Comment 10 Olivier Thomann CLA 2004-01-28 10:20:20 EST
Could you please provide a test case?
Simply attach the source of the compilation unit you are typing. I believe 
this is not the same issue than the original problem.
Comment 11 shmuel siegel CLA 2004-01-28 11:04:44 EST
Created attachment 7611 [details]
The source code that caused the ast creation error

look at the line
private Key key = new Key();
If the line is not complete I get the popup.
Comment 12 Olivier Thomann CLA 2004-01-29 11:44:15 EST
Reproduced the problem.
I am investigating.
Comment 13 Olivier Thomann CLA 2004-01-29 11:55:10 EST
Created attachment 7629 [details]
Reproducable test case

Frederic, you can reproduce it by trying to parse this compilation unit.
Simply add this test case in the ASTConverter2 tests:
	/**
	 * http://dev.eclipse.org/bugs/show_bug.cgi?id=47396
	 */
	public void test0536() throws JavaModelException {
		ICompilationUnit sourceUnit = getCompilationUnit("Converter",
"src", "test0536", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
		ASTNode result = runConversion(sourceUnit, false);
		assertNotNull("No compilation unit", result);
	}

After putting the attached file in the source folder src/test0536.
Comment 14 Frederic Fusier CLA 2004-01-29 16:48:04 EST
*** Bug 50849 has been marked as a duplicate of this bug. ***
Comment 15 Frederic Fusier CLA 2004-01-29 18:19:38 EST
Fixed.

Problem while recovering, ASTConverter.convert(Javadoc) may be called several 
times on same Javadoc. Before we created each times a new Javadoc, but know we 
reuse the same in the global list commentsTable of CU.

So, before adding the javadoc to body declaration, verify that it has not 
already a parent...

Test cases added in ASTConverterTest2 and ASTConverterJavadocTest
Comment 16 shmuel siegel CLA 2004-01-29 18:55:29 EST
Question: what is special about the letter v that caused the problem?
Comment 17 Frederic Fusier CLA 2004-01-30 03:42:15 EST
I've no precise idea about this. My assumption is that jdt-ui at this peculiar 
moment has requested a build of DOM AST nodes hierarchy on Compilation Unit and 
then got the bug...
But, I'm don't know jdt-ui code to be able to understand why it does it at this 
moment.
Comment 18 shmuel siegel CLA 2004-01-30 05:16:53 EST
I don't like closing bugs under this situation. What is bothering me is that
your explanation doesn't account for enough of the symptoms. At the very least,
it should be determined why the bug is reached only under special situations.

I did a little more testing under Integration 20040128 and the original file
that I submitted.
If I alter the line "private Key key = new Key();"
1) erase everything on the line except the word private - no error
2) erase everything on the line except part of the word private - error
3) erase everything on the line except the word private and Key - error
4) erase everything on the line except the word private and Key and some letters
from key - no error

This seems to be dependent on the ability of the parser to make sense of what it
encounters. But only if the bad line is where it is. If the bad line is before
the comment, no problem. I don't know if this is normal for the incremental
parsing, but the question has to be asked.
Comment 19 Markus Keller CLA 2004-01-30 05:45:31 EST
> Question: what is special about the letter v that caused the problem?

shmuel: The exact time of AST calculation is very timing and load dependent.
jdt-ui calculates the AST in the background shortly after the user has stopped
typing. So, nothing is special about the letter v, except if you stop typing
after it ...

The fix in comment 15 sounds reasonable and I'm sure Frédéric knows why it is
fixed now, even if he didn't explain every detail about it.
Comment 20 Frederic Fusier CLA 2004-01-30 06:59:27 EST
I was not clear enough with my answer, when I said "I have no precise idea 
about this...", it was in fact to answer precisely to your question: why when I 
type "v" I got the error...

I didn't really know why it's 'v' and not 'i' or 'a' as for compiler, in this 
case, there's no difference between 'pri' ,'priv' , 'priva', 'privat': there 
are all identifiers. 'private' is different as it's considered as a keyword and 
parse will go through a different way (it's clear with your different test as 
the error didn't occur when whole private is written)...
In fact Markus really answer your question.

Explanation was given when I set the bug to fix, perhaps not clear enough, but 
this explanation was more a reminder for me than an explanation for reporter...

Comment 21 shmuel siegel CLA 2004-01-30 07:30:25 EST
Explanation accepted. Please note that I did not reopen the bug. I was merely
asking for clarification. 

My intention was just to call attention to the fact that the error did not
always occur. If there was something wrong in the parse logic, this was a good
test case. By fixing the AST problem, you were masking the only visible
manifestation of such a problem. My experience says that finding reproducible
problems like this is 90% of the work, fixing them is 10%. I didn't want you to
throw out something that is a good test case for another group. I understand
from your response that you didn't.

I'll drop the subject now.
Comment 22 Olivier Thomann CLA 2004-01-30 10:15:52 EST
Don't worry too much about the 'v'. I guessed that the AST creation happened
after the user stopped typing. I simply created an example that a user can reach
easily.
'v' as the beginning of 'void' :-).
Comment 23 David Audel CLA 2004-02-11 11:08:37 EST
Verified for 3.0M7