Integrated: 8332600: javac uses record components source position during compilation

Vicente Romero vromero at openjdk.org
Thu Jul 18 15:57:38 UTC 2024


On Thu, 11 Jul 2024 21:36:40 GMT, Vicente Romero <vromero at openjdk.org> wrote:

> javac uses the source position of record components to find and later probably remove a given record component during compilation. This could be necessary if annotation processors are present. This is done in part to provide better error messages for silly record definitions like:
> 
> record R(int i, float i) {} // two record components with the same name
> 
> but this is brittle and can backfire if the record is read from a class file as the source positions are not stored there. See [JDK-8332297](https://bugs.openjdk.org/browse/JDK-8332297) for some context
> 
> The idea of this fix is not to use the source position but only the name to find a given record component. This could imply that if the user defines an erroneous record like the one above, then the record could end up with less record components than expected but records like this wouldn't compile anyway
> 
> TIA

This pull request has now been integrated.

Changeset: 245c0866
Author:    Vicente Romero <vromero at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/245c08664896d63ac050ebc23259b23908dafed5
Stats:     47 lines in 3 files changed: 23 ins; 16 del; 8 mod

8332600: javac uses record components source position during compilation

Reviewed-by: jlahoda

-------------

PR: https://git.openjdk.org/jdk/pull/20148


More information about the compiler-dev mailing list