Community
Participate
Working Groups
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
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.
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.
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.)
Created attachment 174699 [details] Proposed patch Proposed patch for both 3.6.x and HEAD. We'll also need to bump the manifest versions.
Olivier, does this patch look okay to you?
Patch looks good. Satyam, please take a look as well.
(In reply to comment #6) Yes, Patch looks good.
+1
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.
I'll release it this evening (Pacific time). Will work on a regression test separately, in the interest of time.
Released to 3.6.1 and to HEAD.
Verified for 3.6.1 RC2 using build M20100825-0800.
Verified for 3.8M2