JDK-8184051 : jdk8 -parameters breaks annotation processor parameter names
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8
  • Priority: P3
  • Status: Resolved
  • Resolution: Won't Fix
  • OS: linux
  • CPU: x86_64
  • Submitted: 2017-06-20
  • Updated: 2017-09-22
  • Resolved: 2017-09-22
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 ----------


Comments
Additional information received from submitter == I have created a full minimal test case here: https://code.moparisthebest.com/moparisthebest/jdk-8184051 Let me know if there are other questions. Issue reproducible on 8u131 and it looks like the bug currently doesn't affect javac 9b177: ==
21-07-2017

There is no test case provided, created the attached test case with given information MethodParameterSpy.java file taken from - https://docs.oracle.com/javase/tutorial/reflect/member/methodparameterreflection.html JavacParameterExample - Created based on the information in the report. == -sh-4.2$ /8u131/fcs/b11/binaries/linux-x64/bin/javac -parameters JavacParameterExample.java -sh-4.2$java_re/jdk/8u131/fcs/b11/binaries/linux-x64/bin/java MethodParameterSpy JavacParameterExample Number of constructors: 0 Number of declared constructors: 1 JavacParameterExample(long,java.util.Date,java.lang.String,java.lang.String) Number of parameters: 4 Parameter class: long Parameter name: personNo Modifiers: 0 Is implicit?: false Is name present?: true Is synthetic?: false Parameter class: class java.util.Date Parameter name: birthDate Modifiers: 0 Is implicit?: false Is name present?: true Is synthetic?: false Parameter class: class java.lang.String Parameter name: firstName Modifiers: 0 Is implicit?: false Is name present?: true Is synthetic?: false Parameter class: class java.lang.String Parameter name: lastName Modifiers: 0 Is implicit?: false Is name present?: true Is synthetic?: false Number of methods: 2 public static void JavacParameterExample.main(java.lang.String[]) Return type: void Generic return type: void Parameter class: class [Ljava.lang.String; Parameter name: args Modifiers: 0 Is implicit?: false Is name present?: true Is synthetic?: false public void JavacParameterExample.BaseModel(long,java.util.Date,java.lang.String,java.lang.String) Return type: void Generic return type: void Parameter class: long Parameter name: personNo Modifiers: 4096 Is implicit?: false Is name present?: true Is synthetic?: true Parameter class: class java.util.Date Parameter name: birthDate Modifiers: 4096 Is implicit?: false Is name present?: true Is synthetic?: true Parameter class: class java.lang.String Parameter name: firstName Modifiers: 4096 Is implicit?: false Is name present?: true Is synthetic?: true Parameter class: class java.lang.String Parameter name: lastName Modifiers: 4096 Is implicit?: false Is name present?: true Is synthetic?: true == Getting the expected result that shows issue is not reproducible.
10-07-2017