question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for Records in Java - false compilation error reported

See original GitHub issue

Short description

Incorrect compilation issue reported by the plugin while using the records.

Since the latest version of IntelliJ, the IDE has started supporting Records in Java introduced as a preview feature in Java-14.

Expected behavior

There should be no compile error reported by the plugin based on the .class generated.

Version information

IDEA Version: IntelliJ IDEA 2020.1 EAP (Community Edition) Build #IC-201.6487.11, built on March 18, 2020 Runtime version: 11.0.6+8-b765.15 x86_64 macOS 10.14.6

Plugin Version: 0.29-EAP

Steps to reproduce

  1. Create a record type as follows

@lombok.AllArgsConstructor public record Java(String version) { }

  1. Create an instance of this class using the appropriate constructor and observe the behavior.

System.out.println(new Java("14").version());

  1. The plugin highlights the “Cannot resolve constructor” message, on the other hand, the code compiles and executes correctly on the IDE.

Sample project

I have reported a reproducible issue on Stackoverflow with the observation and behavior with and without the plugin installed in the IDE.

  • I am able to reproduce this error on the sample project by following the steps described above

Additional information

In general, seems like Lombok in itself needs to support Records as well - https://github.com/rzwitserloot/lombok/issues/2356

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:7
  • Comments:18 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
jqnocommented, Nov 2, 2021

Same issue here. We’re using @Builder on records, but IntelliJ doesn’t recognise them properly.

This doesn’t work:

@Builder
public record MyRecord(String myField) {}

This does:

public record MyRecord(String myField) {
    @Builder public MyRecord {}
}

Both scenarios work when compiling from the command-line with Maven.

So, it’s pretty easy to work around, but we’re using Lombok to get rid of boilerplate, not introduce more of it 😉

7reactions
marx-freedomcommented, Jul 11, 2021

@Builder support would be very helpful 😃 https://youtrack.jetbrains.com/issue/IDEA-266513

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix the top 10 most common compile time errors in Java
Top 10 common Java compile errors and how to fix them · 1. Class and source file mismatch · 2. Improper casing ·...
Read more >
While(false) causes unreachable statement compilation error
Fair. But not the unreachable statement error part. Java architects should have decided: either report both as dead code at compile time or...
Read more >
How to Handle the Incompatible Types Error in Java - Rollbar
The Java incompatible types error happens when a value assigned to a variable or returned by a method is incompatible with the one...
Read more >
Types of Errors in Java with Examples - GeeksforGeeks
Compile Time Errors are those errors which prevent the code from running because of an incorrect syntax such as a missing semicolon at...
Read more >
5 Record Classes - Java - Oracle Help Center
Repeating the record class's components in the signature of the canonical constructor can be tiresome and error-prone. To avoid this, you can declare...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found