Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6346973

JSR 269 directSupertypes(Mirror m) causes java.lang.StackOverflowError

XMLWordPrintable

      As shown in in this simple example. APT takes an invalid TypeParameter and causes 'StackOverflowError'.
      it was only at 5 th iteration of Visitor.

      How to reproduce this case.
      --------------------------
      bash-3.00$ cat CaseAP.java
      import java.util.*;
      import javax.annotation.processing.*;
      import javax.lang.model.element.*;
      import javax.lang.model.type.*;
      import javax.lang.model.util.*;
      import static javax.lang.model.SourceVersion.*;
      import static javax.lang.model.type.TypeKind.*;

      @SupportedAnnotationTypes("*")
      @SupportedSourceVersion(RELEASE_6)
      @SupportedOptions("-verbose")
      public class CaseAP extends AbstractProcessor {
          public void init(ProcessingEnvironment penv) {
              super.init(penv);
          }
          public static Types types;
          public static Types getTypes() {
              return types;
          }
          public boolean process(Set<? extends TypeElement> typeElementSet,
                  RoundEnvironment renv) {
              if ( renv.errorRaised()) {
                  System.out.println(" ******* Error raised ... ");
                  return false;
              }
              Elements elementUtils = processingEnv.getElementUtils();
              types = processingEnv.getTypeUtils();
              Vector<TypeMirror> listArrayElementList = new Vector<TypeMirror>();
              Void p = null;
              SimpleTypeMirrorVisitor typeVisitor = new SimpleTypeMirrorVisitor();
              for( TypeElement element : renv.getSpecifiedTypeElements()) {
                  List<? extends Element > list = element.getEnclosedElements();
                  for( Element e : list) {
                      if (e instanceof TypeElement ) {
                          TypeElement te = (TypeElement) e;
                          te.asType().accept(typeVisitor, p);
                          List<? extends TypeParameterElement> list_ = te.getTypeParameters();
                          for(TypeParameterElement tpe : list_) {
                              tpe.getGenericElement().asType().accept(typeVisitor,p);
                              List<? extends TypeMirror> types = tpe.getBounds();
                              for(TypeMirror tm : types) {
                                  tm.accept(typeVisitor,p);
                              }
                          }
                      }
                  }
                  element.asType().accept(typeVisitor,p);
              }
              return true ;
          }
      }
      class SimpleTypeMirrorVisitor extends SimpleTypeVisitor6 <Void, Void> {
          private static int counter=0;
          protected Void defaultAction(TypeMirror mirror, Void p ) {
              List <? extends TypeMirror> list = CaseAP.getTypes().directSupertypes(mirror);
              for(TypeMirror tm : list) {
                  if ( tm != null ) {
                      tm.accept(this,p);
                  }
              }
              counter++;
              System.out.println(" visited for = "+counter);
              return p;
          }
      }
      bash-3.00$ cat Case1.java
      import java.util.Vector;
      import java.io.*;
      public class Case1 {
          private String message;
          private int intI;
          private float floatF;

          class MyInnerClass <T extends Case12> {
              public T myT;
              public T getMyT() {
                  return myT;

              }

          }

      }
      bash-3.00$ ksh compile.sh
      Case1.java:8: cannot find symbol
      symbol : class Case12
      location: class Case1
          class MyInnerClass <T extends Case12> {
                                        ^
       visited for = 1
       visited for = 2
       visited for = 3
       visited for = 4


      An annotation processor threw an uncaught exception.
      Consult the following stack trace for details.
      java.lang.StackOverflowError
              at com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:2924)
              at com.sun.tools.javac.code.Types.supertype(Types.java:1510)
              at com.sun.tools.javac.model.JavacTypes.directSupertypes(JavacTypes.java:90)
              at SimpleTypeMirrorVisitor.defaultAction(CaseAP.java:55)
              at SimpleTypeMirrorVisitor.defaultAction(CaseAP.java:52)
              at javax.lang.model.util.SimpleTypeVisitor6.visitError(SimpleTypeVisitor6.java:155)
              at com.sun.tools.javac.code.Type$ErrorType.accept(Type.java:1155)
              at SimpleTypeMirrorVisitor.defaultAction(CaseAP.java:58)
              at SimpleTypeMirrorVisitor.defaultAction(CaseAP.java:52)
              at javax.lang.model.util.SimpleTypeVisitor6.visitError(SimpleTypeVisitor6.java:155)
              at com.sun.tools.javac.code.Type$ErrorType.accept(Type.java:1155)
              at SimpleTypeMirrorVisitor.defaultAction(CaseAP.java:58)
              at SimpleTypeMirrorVisitor.defaultAction(CaseAP.java:52)
              at javax.lang.model.util.SimpleTypeVisitor6.visitError(SimpleTypeVisitor6.java:155)^C at com.sun.tools.javac.code.Type$ErrorType.accept(Type.java:1155)
              at SimpleTypeMirrorVisitor.defaultAction(CaseAP.java:58)
              at SimpleTypeMirrorVisitor.defaultAction(CaseAP.java:52)
              at javax.lang.model.util.SimpleTypeVisitor6.visitError(SimpleTypeVisitor6.java:155)
              at com.sun.tools.javac.code.Type$ErrorType.accept(Type.java:1155)
              at SimpleTypeMirrorVisitor.defaultAction(CaseAP.java:58)
              at SimpleTypeMirrorVisitor.defaultAction(CaseAP.java:52)
              at javax.lang.model.util.SimpleTypeVisitor6.visitError(SimpleTypeVisitor6.java:155)
              at com.sun.tools.javac.code.Type$ErrorType.accept(Type.java:1155)
              at SimpleTypeMirrorVisitor.defaultAction(CaseAP.java:58)
              at SimpleTypeMirrorVisitor.defaultAction(CaseAP.java:52)
              at javax.lang.model.util.SimpleTypeVisitor6.visitError(SimpleTypeVisitor6.java:155)
              at com.sun.tools.javac.code.Type$ErrorType.accept(Type.java:1155)
              at SimpleTypeMirrorVisitor.defaultAction(CaseAP.java:58)
              at SimpleTypeMirrorVisitor.defaultAction(CaseAP.java:52)
              at javax.lang.model.util.SimpleTypeVisitor6.visitError(SimpleTypeVisitor6.java:155)
              at com.sun.tools.javac.code.Type$ErrorType.accept(Type.java:1155)
              at SimpleTypeMirrorVisitor.defaultAction(CaseAP.java:58)
              at SimpleTypeMirrorVisitor.defaultAction(CaseAP.java:52)
      .....

            sseligmasunw Scott Seligman (Inactive)
            vvegurusunw Viswadeep Veguru (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: