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

Binary/Qualified name is wrong? Begins with: <any?>$

    XMLWordPrintable

Details

    Description

      ADDITIONAL SYSTEM INFORMATION :
      I doubt it matters but the annotation processors are still marked @SupportedSourceVersion(SourceVersion.RELEASE_8) and I'm running this on Gradle 5.3.1.

      A DESCRIPTION OF THE PROBLEM :
      I'm running an annotation processor that I've wrote. It ran fine on JDK 8 and now I'm experiencing a problem on JDK 12, I have not tested JDK 9, 10, or 11.

      I have a TypeElement and I want to retrieve its binary name to pass to Class.forName. I use javax.lang.model.util.Elements.getBinaryName(TypeElement) and it returns a garbage value <any?>$OuterClass.InnerClass instead of the expected example3.OuterClass$InnerClass.

      I attempted to replace getBinaryName with TypeElement.getQualifiedName (even though it wouldn't quite work for an inner class) but it gives me the same garbage result.

      REGRESSION : Last worked in version 8u201

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      The TypeElement was obtained by catching a MirroredTypeException like so:

              try {
                  exampleAnnotation.value();
                  throw new IllegalStateException("Expected a MirroredTypeException.");
              } catch (MirroredTypeException ex) {
                  return (TypeElement) types.asElement(ex.getTypeMirror());
              }

      And here's the definition of ExampleAnnotation:

      package example1;

      @Target(PACKAGE)
      @Retention(RUNTIME)
      @Documented
      public @interface ExampleAnnotation {
          Class<? extends Derived> value() default Derived.class;

          interface Derived<A extends Annotation> extends Base<A> {
              String foo();
          }
      }

      And here's the instance of the annotation that the processor is accessing in package-info.java:

      @ExampleAnnotation(OuterClass.InnerClass.class)
      package example2;
      import example1.ExampleAnnotation;

      I've also tried the fully qualified name example3.OuterClass.InnerClass.class but that also results in garbage: <any?>$example3.OuterClass.InnerClass.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      javax.lang.model.util.Elements.getBinaryName should return example3.OuterClass$InnerClass

      and TypeElement.getQualifiedName should return example3.OuterClass.InnerClass
      ACTUAL -
      javax.lang.model.util.Elements.getBinaryName and TypeElement.getQualifiedName are erroneously returning <any?>$OuterClass.InnerClass or <any?>$example3.OuterClass.InnerClass depending on if I use the imported name vs fully qualified name, respectively.

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              darcy Joe Darcy
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated: