Skip to content

Extension suggests empty constructor for Records where only canonical constructor exists #4134

@fdesu

Description

@fdesu

Hi, I recently stumbled upon a tiny issue with records that have only canonical constructor where the extension both:

  1. Successfully compiles (at least it doesn't show an error) code that uses the empty record constructor
  2. Forcing recompilation (incremental/full - doesn't make any difference) or rebuilding the project using extension also passes without any issues. Maven build fails though.

Given the above, the usage of the constructor without parameters doesn't popup in the problems tab.

A quick, and fairly simple, example can be reproduced with such record:

public record SimpleRecord(String fileName, Long lineNumber) {
}

Here're a few screenshot from the call site:
Image
Image

Important to note, that, once I type e.g. new SimpleRecord("abc") (i.e. try to invoke a non-existent constructor for the first arg), the extension properly catches this error and highlights it in the "problems" tab. And also worth mentioning that adding an additional constructor solves the issue, so the empty constructor isn't being suggested in this case.

Not sure if this problem is caused by the extension itself or perhaps the JDTLS is the better place to raise the issue?

Also, I don't mind diving deeper into this issue and fix it.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions