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

jdk8 -parameters breaks annotation processor parameter names

    XMLWordPrintable

Details

    • x86_64
    • linux

    Description

      FULL PRODUCT VERSION :
      java version "1.8.0_131"
      Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
      Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux 4.10.16-1-ck-sandybridge #1 SMP PREEMPT Sun May 14 10:01:03 EDT 2017 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      In an annotation processor, I am getting parameter names from a constructor. They were incorrect, but I noticed they worked with javac 1.6, and when I removed the -parameters argument for javac 1.8 they were correct too, so the -parameters compiler flag causes the issue.

      The constructor in question is:

      FieldPerson(long personNo, Date birthDate, String firstName, String lastName)

      javac 1.6, and 1.8 without -parameters sees:

      FieldPerson(long personNo, java.util.Date birthDate, java.lang.String firstName, java.lang.String lastName)

      javac 1.8 with -parameters sees:

      FieldPerson(long personNo, java.util.Date firstName, java.lang.String lastName, java.lang.String arg3)

      So somehow, parameter names are shifted to the left one starting at index 1 not 0.

      This bug effectively lets you choose to have parameter names available at compile time or runtime but not both.

      REGRESSION. Last worked in version 6u45

      ADDITIONAL REGRESSION INFORMATION:
      I think this is only because -parameters was introduced with 1.8

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Correct parameter names
      ACTUAL -
      Incorrect/shifted parameter names

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /* complete example code is here:
      https://code.moparisthebest.com/moparisthebest/JdbcMapper/src/68c1c0482e56c1a2a3ea842a6a71fea3e4444738/jdbcmapper/src/main/java/com/moparisthebest/jdbc/codegen/CompileTimeRowToObjectMapper.java#L88
      just uncomment that and compile with maven and an exception will be shown with the problem

      here is code that could run on any TypeMirror someTypeMirror from a AbstractProcessor
      */

      if(someTypeMirror.getKind() == TypeKind.DECLARED) {
      final List<? extends Element> methodsAndConstructors = ((TypeElement) ((DeclaredType) someTypeMirror).asElement()).getEnclosedElements();
      processingEnv.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING, methodsAndConstructors.stream().filter(e -> e.getKind() == ElementKind.CONSTRUCTOR && e.getModifiers().contains(Modifier.PUBLIC)).map(e -> e.toString() +
      ": '" + ((ExecutableElement) e).getParameters().stream().map(param -> param.asType() + " " + param.getSimpleName().toString()).collect(java.util.stream.Collectors.joining(", ")) + "'"
      ).collect(java.util.stream.Collectors.joining(", ")));
      }
      ---------- END SOURCE ----------

      Attachments

        1. JavacParameterExample.java
          0.4 kB
          Fairoz Matte
        2. MethodParameterSpy.java
          4 kB
          Fairoz Matte

        Activity

          People

            jlahoda Jan Lahoda
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: