Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 320195 - Eclipse hangs when processing annotation
Summary: Eclipse hangs when processing annotation
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: APT (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 3.6.1   Edit
Assignee: Walter Harley CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-18 12:26 EDT by Sekhar Ravinutala CLA
Modified: 2011-09-14 11:30 EDT (History)
5 users (show)

See Also:
Olivier_Thomann: review+


Attachments
Proposed patch (2.95 KB, patch)
2010-07-20 02:11 EDT, Walter Harley CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sekhar Ravinutala CLA 2010-07-18 12:26:35 EDT
Build Identifier: 20100218-1602

Eclipse is hanging if process() does not loop through annotations. E.g.,

This works OK:
public boolean process(...) {
  for (TypeElement annotation : annotations) {
    // Do something
  }

  return true;
}

But, this one without looping through annotations hangs:
public boolean process(...) {
  // Do something

  return true;
}

Reproducible: Always

Steps to Reproduce:
1. Create process() with a simple trace, with return true
2. Try to build
3. Eclipse starts to build and goes on forever, with CPU high - looks like an infinite loop
Comment 1 Walter Harley CLA 2010-07-18 16:46:49 EDT
Can you clarify the "do something"?  E.g., does it work if you literally just return true from the process() method?

Does your processor also hang if you run it from javac?

Could you take a thread dump during the hang (as described in http://wiki.eclipse.org/How_to_report_a_deadlock) and attach it here?  Thanks.
Comment 2 Sekhar Ravinutala CLA 2010-07-18 18:02:56 EDT
No hang for just return true, but looks like the problem happens when there's an exception (even if caught). When running within the loop, I guess there's no exception, so no problem. The below code will hang, I've verified - please try:

@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes({"com.allurefx.test.FooAnnotation"})
public class FooAnnotationProcessor extends AbstractProcessor {
	@Override
	public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
		try {
			final Writer writer = processingEnv.getFiler().createSourceFile("Whatever").openWriter();
			writer.append("class Whatever{}");
			writer.close();
		} catch (IOException e) {
			processingEnv.getMessager().printMessage(Kind.ERROR, e.toString());
		}
		
		return true;
	}
}

Unfortunately, I'm able to get jvisualvm to dump (the button is grayed out), but the above should give you an idea of what's going on.
Comment 3 Walter Harley CLA 2010-07-18 21:59:09 EDT
Ok, I see what's going on.

You're asking it to generate a source file in each round of processing, which triggers another round of processing, and so on.

Per the spec, it _should_ throw a FilerException in the second round, because it is not legal to ask for the same file to be generated twice.  However, this is not yet implemented in the Eclipse processing implementation (see the TODO in IdeFilerImpl).

I'll work on implementing that exception.  As a workaround, you can do what you would need to do anyway if the exception was correctly implemented; that is, don't generate the same file twice during processing.  (Typically this is not a problem, but it happens in this example because your processor is not paying attention to the annotations it's processing.)
Comment 4 Walter Harley CLA 2010-07-20 02:11:28 EDT
Created attachment 174699 [details]
Proposed patch

Proposed patch for both 3.6.x and HEAD.  We'll also need to bump the manifest versions.
Comment 5 Walter Harley CLA 2010-07-20 02:11:57 EDT
Olivier, does this patch look okay to you?
Comment 6 Olivier Thomann CLA 2010-07-20 11:05:56 EDT
Patch looks good.
Satyam, please take a look as well.
Comment 7 Satyam Kandula CLA 2010-07-21 07:11:17 EDT
(In reply to comment #6)
Yes, Patch looks good.
Comment 8 Olivier Thomann CLA 2010-07-21 10:12:00 EDT
+1
Comment 9 Olivier Thomann CLA 2010-07-26 10:48:48 EDT
Walter, please release this patch asap so it can be tested with the upcoming M-build.
Would also be nice to get a regression test for this.
Thanks.
Comment 10 Walter Harley CLA 2010-07-26 12:56:02 EDT
I'll release it this evening (Pacific time).  Will work on a regression test separately, in the interest of time.
Comment 11 Walter Harley CLA 2010-07-27 02:01:26 EDT
Released to 3.6.1 and to HEAD.
Comment 12 Jay Arthanareeswaran CLA 2010-08-27 06:04:38 EDT
Verified for 3.6.1 RC2 using build M20100825-0800.
Comment 13 Olivier Thomann CLA 2011-09-14 11:30:07 EDT
Verified for 3.8M2