When processing a source file not declared to be in any package with a PackageElement obtained from Elements.getPackageElement(), getEnclosedElements() elicits a duplcate class error and this error:
"an annotation processor threw an uncaught exception.
Consult the following stack trace for details.
com.sun.tools.javac.jvm.ClassReader$BadClassFile: bad class file: ./dir1/test0.java
file does not contain class dir1.test0
Please remove or make sure it appears in the correct subdirectory of the classpath.
at com.sun.tools.javac.main.JavaCompiler.complete(JavaCompiler.java:599)
at com.sun.tools.javac.jvm.ClassReader.fillIn(ClassReader.java:1777)
at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:1700)
...."
%javac -proc:none b6341534.java
%javac -proc:only -processor b6341534 -cp . ./src/*.java
---source files and processor souce below-------
% cat src/test0.java
//package dir1;
public class test0 { }
% cat src/test1.java
package dir1;
public class test1 { }
- - - - - - - - - - - - - - - - - - - -- - - -- -
% cat b6341534.java
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
import static javax.lang.model.util.ElementFilter.*;
import static javax.tools.Diagnostic.Kind.*;
import java.util.*;
import java.util.Set;
@SupportedAnnotationTypes({"*"})
@SupportedSourceVersion(javax.lang.model.SourceVersion.RELEASE_6)
public class b6341534 extends AbstractProcessor {
static int r = 0;
static Elements E = null;
static Messager msgr = null;
public void init(ProcessingEnvironment penv) {
processingEnv = penv;
msgr = penv.getMessager();
E = penv.getElementUtils();
}
//Create directory 'dir1' and a test class in dir1
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv)
{
if(!renv.errorRaised() && !renv.processingOver()){
r++;
for( TypeElement t : renv.getSpecifiedTypeElements() )
System.out.println("Round"+r+ ": " + t.toString());
try {
PackageElement PE = E.getPackageElement("dir1");
List<? extends Element> LEE = PE.getEnclosedElements(); /* <=This line elicits the error message. */
for(Element e : LEE) System.out.println("found " + e.toString() + " in dir1.");
}
catch(NullPointerException npe) {
msgr.printMessage(ERROR,npe.toString());
//npe.printStackTrace();
return false;
}
}
if( renv.errorRaised() ) { msgr.printMessage(ERROR, "FAILED");}
return true;
}
}
"an annotation processor threw an uncaught exception.
Consult the following stack trace for details.
com.sun.tools.javac.jvm.ClassReader$BadClassFile: bad class file: ./dir1/test0.java
file does not contain class dir1.test0
Please remove or make sure it appears in the correct subdirectory of the classpath.
at com.sun.tools.javac.main.JavaCompiler.complete(JavaCompiler.java:599)
at com.sun.tools.javac.jvm.ClassReader.fillIn(ClassReader.java:1777)
at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:1700)
...."
%javac -proc:none b6341534.java
%javac -proc:only -processor b6341534 -cp . ./src/*.java
---source files and processor souce below-------
% cat src/test0.java
//package dir1;
public class test0 { }
% cat src/test1.java
package dir1;
public class test1 { }
- - - - - - - - - - - - - - - - - - - -- - - -- -
% cat b6341534.java
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
import static javax.lang.model.util.ElementFilter.*;
import static javax.tools.Diagnostic.Kind.*;
import java.util.*;
import java.util.Set;
@SupportedAnnotationTypes({"*"})
@SupportedSourceVersion(javax.lang.model.SourceVersion.RELEASE_6)
public class b6341534 extends AbstractProcessor {
static int r = 0;
static Elements E = null;
static Messager msgr = null;
public void init(ProcessingEnvironment penv) {
processingEnv = penv;
msgr = penv.getMessager();
E = penv.getElementUtils();
}
//Create directory 'dir1' and a test class in dir1
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv)
{
if(!renv.errorRaised() && !renv.processingOver()){
r++;
for( TypeElement t : renv.getSpecifiedTypeElements() )
System.out.println("Round"+r+ ": " + t.toString());
try {
PackageElement PE = E.getPackageElement("dir1");
List<? extends Element> LEE = PE.getEnclosedElements(); /* <=This line elicits the error message. */
for(Element e : LEE) System.out.println("found " + e.toString() + " in dir1.");
}
catch(NullPointerException npe) {
msgr.printMessage(ERROR,npe.toString());
//npe.printStackTrace();
return false;
}
}
if( renv.errorRaised() ) { msgr.printMessage(ERROR, "FAILED");}
return true;
}
}
- duplicates
-
JDK-6458968 com.sun.tools.javac.code.Symbol$CompletionFailure is thrown from the API calls
- Closed
-
JDK-6400041 javax.lang.model.element.TypeElement.getKind() throws CompletionFailure
- Closed
- relates to
-
JDK-6441871 suppress stack trace after CompletionFailure in annotation progressing
- Closed
-
JDK-6976744 test/tools/javac/processing/6430209/T6430209.java passes incorrectly
- Closed