Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 400767 - Endless loop in AbstractCommentParser caused by JavadocParser
Summary: Endless loop in AbstractCommentParser caused by JavadocParser
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8.1   Edit
Hardware: PC Windows 7
: P3 major (vote)
Target Milestone: 4.3 M6   Edit
Assignee: Manoj N Palat CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-14 04:01 EST by Thomas Bröker CLA
Modified: 2013-03-12 04:14 EDT (History)
3 users (show)

See Also:


Attachments
Project to reproduce the bug (5.93 KB, application/x-zip-compressed)
2013-02-14 04:01 EST, Thomas Bröker CLA
no flags Details
Proposed Patch using the suggested fix (1.29 KB, patch)
2013-02-21 06:37 EST, Manoj N Palat CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Bröker CLA 2013-02-14 04:01:36 EST
Created attachment 227060 [details]
Project to reproduce the bug

OVERVIEW
Selecting code fragments or using "Open Declaration" on a selected part of code causes an endless loop in AbstractCommentParser:177 and eclipse generates 100% cpu  load on one core. If main thread gets in the loop eclipse is not responding and can only be terminated by task manager with losing all unsaved code.

REPRODUCTION
Import the attached project in a clean workspace. Open the class "Bug" and scroll to the "TODO" task tag. Double click on "componentShown" in the next line and press F3.

RESULT
Eclipse is hanging in an endless lopp with 100% cpu load on one core.

EXPECTED
Eclipse should jump to the marked method.

ADDITIONAL INFORMATION
The problem is caused by the JavadocParse. The parser tries to parse the package-info.java of a referenced package. After that the actual source is parsed, but the scanner used by the parser has still the source of the package-info.java. This leads to parsing the same source range over and over again.

WORKAROUND
Disable javadoc comment processing in compiler options.

POSSIBLE FIX
Initialising the source of the Scanner in org.eclipse.jdt.internal.compiler.parser.JavadocParser:94

CURRENT CODE
public boolean checkDeprecation(int commentPtr) {
  [...]
  // Parse
  try {
    this.source = this.sourceParser.scanner.source;
    [...]
  } finally {
    this.source = null; // release source as soon as finished
  }
  return this.deprecated;
}

CODE FIXING THE PROBLEM
public boolean checkDeprecation(int commentPtr) {
  [...]
  // Parse
  try {
    this.source = this.sourceParser.scanner.source;
    this.scanner.setSource(this.source); //updating source in scanner
    [...]
  } finally {
    this.source = null; // release source as soon as finished
    this.scanner.setSource((char[]) null); //release source in scanner
  }
  return this.deprecated;
}
Comment 1 Srikanth Sankaran CLA 2013-02-14 05:07:26 EST
Manoj, As this causes data loss, we need to fix this asap. I have set the
target to M6. Please take a look.
Comment 2 Srikanth Sankaran CLA 2013-02-14 05:08:26 EST
(In reply to comment #0)

> POSSIBLE FIX
> Initialising the source of the Scanner in
> org.eclipse.jdt.internal.compiler.parser.JavadocParser:94

Thomas, Thanks for the detailed analysis and a possible fix.
Comment 3 Manoj N Palat CLA 2013-02-21 06:37:23 EST
Created attachment 227393 [details]
Proposed Patch using the suggested fix

Srikanth, The bug was reproduced with the given attachment. The fix suggested was verified to solve the issue as mentioned by Thomas. The above patch (created out of the suggested fix) has cleared all the tests as well.
Comment 4 Jay Arthanareeswaran CLA 2013-03-03 23:25:15 EST
(In reply to comment #3)
> Created attachment 227393 [details]
> Proposed Patch using the suggested fix

Patch looks good. Manoj, do you think it's possible to come up with a regression test for this scenario?
Comment 5 Srikanth Sankaran CLA 2013-03-10 03:50:18 EDT
(In reply to comment #4)

> Patch looks good. Manoj, do you think it's possible to come up with a
> regression test for this scenario?

Manoj, Have you had a chance to look into this ?
Comment 6 Jay Arthanareeswaran CLA 2013-03-11 14:11:54 EDT
Patch and test released in separate commits and the current HEAD is here:

http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=07e9b0e8791371fe37d0b3154d25a43e023b50c9
Comment 7 Jay Arthanareeswaran CLA 2013-03-11 14:12:46 EDT
Resolving.
Comment 8 Jay Arthanareeswaran CLA 2013-03-12 04:14:54 EDT
Verified for 4.3 M6 with build I20130311-2000