immutables / io

Experimental classes related to the next generation of Immutables library

Home Page:http://immutables.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Static factory argument order changed in 2.8.x

marquiswang opened this issue · comments

We noticed a behavioral change in the generated static factory in 2.8.x, when inheriting fields from a parent class.

For example, with the following code:

public interface Foo {
    @Value.Parameter
    int a();
}

@Value.Immutable
public interface Bar extends Foo {
    @Value.Parameter
    int b();
}

In 2.7.x Immutables generates

public static ImmutableBar of(int b, int a) {
    return new ImmutableBar(b, a);
}

and in 2.8.x it generates:

public static ImmutableBar of(int a, int b) {
    return new ImmutableBar(a, b);
}

I think that the new behavior is better, and in a few cases in our codebase we'd explicitly changed the subclass to be something like the following in order to force the parameter order.

@Value.Immutable
public interface Bar extends Foo {
    @Override
    @Value.Parameter
    int a();

    @Value.Parameter
    int b();
}

However, we have great concerns about the safety of this migration - if the parameters are all of the same type, then reordering parameters can lead to really dangerous bugs.

Do you have any suggestions for how to migrate to 2.8.x and higher? I'm thinking that some kind of flag that we can pass to Immutables to detect if all fields are the same type AND there is a parent class that provides some fields, then emit a warning unless some annotation is added to the class indicating that it was checked?

Oops wrong project.