Randgalt / record-builder

Record builder generator for Java records
Apache License 2.0
758 stars 55 forks source link

Remove unused variable in RecordBuilder #11

Closed TedCassirer closed 4 years ago

TedCassirer commented 4 years ago

Minor issue There's an unused variable r in the builder if the record only have 1 field. Spotbugs flagged the generated source in my project because of it. This should fix the issue.

Example:

@RecordBuilder
public record MyRecord(long id) implements MyRecordBuilder.With {}

Generates ->

@Generated("io.soabase.recordbuilder.core.RecordBuilder")
public class MyRecordBuilder {
        private long id;

...
....
        /**
         * Return a new instance of {@code MyRecord} with a new value for {@code id}
         */
        @Generated("io.soabase.recordbuilder.core.RecordBuilder")
        default MyRecord withId(long id) {
            var r = (MyRecord)(Object)this;  //<---UNUSED
            return new MyRecord(id);
        }
}

I could just exclude the generated sources from spotbugs if you consider this a non bug

Randgalt commented 4 years ago

Thanks again.

TedCassirer commented 4 years ago

Ah, I commited a misstake. Noticed it immediately after creating the PR. Sorry! I'll push the correct fix in a min

Randgalt commented 4 years ago

lol - I should test these before I merge

TedCassirer commented 4 years ago

Disregard that. I just messed up updating my dependencies in my project causing me to build with the incorrect fix. It works as intended.

        /**
         * Return a new instance of {@code MyRecord} with a new value for {@code id}
         */
        @Generated("io.soabase.recordbuilder.core.RecordBuilder")
        default MyRecord withId(long id) {
            return new MyRecord(id);
        }
Randgalt commented 4 years ago

I apologize, Github isn't giving you credit for these PRs due to: https://github.com/isaacs/github/issues/1368