Bug 99507 - [javadoc] Infinit loop in DocCommentParser
Summary: [javadoc] Infinit loop in DocCommentParser
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 RC3   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 99508 99509 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-06-11 07:18 EDT by julien CLA
Modified: 2005-06-16 13:38 EDT (History)
1 user (show)

See Also:


Attachments
Patch to fix this issue (1.00 KB, patch)
2005-06-13 09:32 EDT, Frederic Fusier CLA
no flags Details | Diff
Test case added to ASTConverterJavadocTest (1.03 KB, patch)
2005-06-13 09:32 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 julien CLA 2005-06-11 07:18:29 EDT
In 31RC1, in case of the following JavaDoc,

/**
 * @param test
 */

JDT fails in infinit loop at at line 857 of the 
AbstractCommentParser.parseParam():

while (readToken() != TerminalTokens.TokenNameWHITESPACE) {
	this.currentTokenType = -1;
	end = hasMultiLines ? this.lineEnd: 
this.scanner.getCurrentTokenEndPosition();
}

If fact, the current token is TokenNameEOF.
Comment 1 Olivier Thomann CLA 2005-06-11 12:49:18 EDT
*** Bug 99508 has been marked as a duplicate of this bug. ***
Comment 2 Olivier Thomann CLA 2005-06-11 12:49:56 EDT
*** Bug 99509 has been marked as a duplicate of this bug. ***
Comment 3 Philipe Mulet CLA 2005-06-12 16:45:49 EDT
+1 for RC3

Dirk - I think we should fix this for RC3.
Comment 4 Dirk Baeumer CLA 2005-06-13 02:54:55 EDT
+1.
Comment 5 Frederic Fusier CLA 2005-06-13 04:41:25 EDT
Can you attach your compilation unit to this bug?
I'm not able to reproduce the infinite loop, thx
Comment 6 Frederic Fusier CLA 2005-06-13 09:11:30 EDT
I got it. Here's sample which makes this loop infinite:
X.java:
public class X {
}
/**
 * @param test*/<EOF>

IMO, example to get this infinite loop is really specific and seems not
something really easy to reproduce (I really spend lot of time before get it...)

So, except if you have another simple test case user can write easily, I would
like you to decrease severity to major (perhaps normal would be better finally). 
Comment 7 Frederic Fusier CLA 2005-06-13 09:32:03 EDT
Created attachment 22917 [details]
Patch to fix this issue

Comment parser expects a separator after tag name or following identifier.
When cu ends with javadoc and this comment ends with tag name or identifier
*just* followed by end of comment (ie. */), it reaches EOF and falls into this
infinite loop...
Comment 8 Frederic Fusier CLA 2005-06-13 09:32:50 EDT
Created attachment 22918 [details]
Test case added to ASTConverterJavadocTest
Comment 9 julien CLA 2005-06-13 10:48:42 EDT
In fact, for us, it is very easy to reproduce it if you use the "method" 
comment template, which is defined in JDT Preferences. However, the getter and 
setter comment template work fine.

public class Person {
/**
 * @param test
 */
 void test()
 {
 }
}
Comment 10 Frederic Fusier CLA 2005-06-13 11:11:57 EDT
How can you get a @param tag although your method have no argument?
Comment 11 Frederic Fusier CLA 2005-06-13 11:46:08 EDT
I'm still unable to reproduce infinite loop with comment 9 example.
I've tried many variations (Unix format, only tabs, only spaces, UTF-8 encoding,
etc.) without any success.

I'm confident that fix will solve this problem but I really want to understand 
why you easily get it and not me... May you attach a compilation with which you
get this issue, perhaps this will help me?

TIA
Comment 12 Frederic Fusier CLA 2005-06-13 13:15:26 EDT
Fixed, patch released in HEAD
Comment 13 julien CLA 2005-06-13 15:32:28 EDT
Here is our code:
        String source = "/**\n@param country*/";
        ASTParser parser = ASTParser.newParser(AST.JLS3);
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	parser.setSource(source.toCharArray());
	ASTNode root = (ASTNode) parser.createAST(null);
Comment 14 Frederic Fusier CLA 2005-06-14 03:57:20 EDT
OK, but why did you reopen this bug?
1) It passes with the fix
2) It's not so different than my comment 6 sample also fixed by the code I
released yesterday...
As I said in this comment, your sample is really not a common test case and just
add a space anywhere after "country" will avoid this issue...
=> modify severity and set as resolved
Comment 15 Frederic Fusier CLA 2005-06-14 04:06:50 EDT
I've added test case #testBug99507b in ASTConverterJavadocTest for your specific
comment 13 code snippet
Comment 16 Maxime Daniel CLA 2005-06-16 12:49:25 EDT
Verified using build N20050616-0010 + JDT Core HEAD.