This will be reported on a very simple record:
public record SomeClass(String firstName, String lastName, String middleName) { }
Thanks for opening your first issue here! :smiley:
Please check our contributing guideline. Especially when you report a problem, make sure you share a Minimal, Complete, and Verifiable example to reproduce it in this issue.
Same with Spotbugs 4.2.0:
public record Metadata(
int zoom, double minX, double maxX, double minY, double maxY,
long minTime, long maxTime, double speedup
) { }
Spotbugs reports the following warning:
app.gpx_animator.core.renderer.Metadata.equals(Object) is unusual
--
Bug type EQ_UNUSUAL (click for details)
In class app.gpx_animator.core.renderer.Metadata
In method app.gpx_animator.core.renderer.Metadata.equals(Object)
At Metadata.java:[line 4]
Details:
This class doesn't do any of the patterns we recognize for checking
that the type of the argument is compatible with the type of the this
object. There might not be anything wrong with this code, but it is
worth reviewing.
My expectation: Spotbugs should accept the default implementation of Java records.
Same happens on recently released JDK 16+SpotBugs 4.2.2
note: equals() invokes dynamically generated codes, so static analysis cannot handle it property:
https://dzone.com/articles/a-first-look-at-records-in-java-14
public final boolean equals(java.lang.Object);
descriptor: (Ljava/lang/Object;)Z
flags: (0x0011) ACC_PUBLIC, ACC_FINAL
Code:
stack=2, locals=2, args_size=2
0: aload_0
1: aload_1
2: invokedynamic #30, 0 // InvokeDynamic #0:equals:(LRecordClass;Ljava/lang/Object;)Z
7: ireturn
SpotBugs needs to ignore classes that extend java.lang.Record.
Note that users can write their own equals and hash code implementations for records.
SpotBugs should only execute the equals check if the class extending Record has the implementation of an own equal method.