You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm generating builders for some existing code with POJOs that looks like this:
@Buildable(editableEnabled = false)
public class Boxy {
private final int p1;
private final int p2;
public Boxy(int p1, Integer p2) {
this.p1 = p1;
// some business logic to default p2 in the p2 == null case.
this.p2 = p2;
}
public int getP1() {
return p1;
}
public int getP2() {
return p2;
}
}
The generated code fails to compile.
[ERROR] /Users/kwall/src/sundrio/examples/builder/hello-inheritance/target/generated-sources/annotations/io/sundr/examples/BoxyFluent.java:[19,11] cannot find symbol
[ERROR] symbol: method withP2(int)
[ERROR] /Users/kwall/src/sundrio/examples/builder/hello-inheritance/target/generated-sources/annotations/io/sundr/examples/BoxyBuilder.java:[25,13] cannot find symbol
[ERROR] symbol: method withP2(int)
[ERROR] location: variable fluent of type io.sundr.examples.BoxyFluent<?>
[ERROR] /Users/kwall/src/sundrio/examples/builder/hello-inheritance/target/generated-sources/annotations/io/sundr/examples/BoxyBuilder.java:[36,11] cannot find symbol
[ERROR] symbol: method withP2(int)
[ERROR] /Users/kwall/src/sundrio/examples/builder/hello-inheritance/target/generated-sources/annotations/io/sundr/examples/BoxyBuilder.java:[43,52] cannot find symbol
[ERROR] symbol: method getP2()
The code gen has omitted to generate a withP2() method (or the field) in the fluent, yet the builder implementation assumes it will be present. This suggests an inconsistency in the sundrio implementation.
I can imagine to support this use-case, sundrio would need to special casing to use the boxed type in the fluent rather than the primitive. I can well imagine there are gotchas in the detail..
I want to know if this is considered a defect, or an unsupported use-case? If the latter, I wonder if calling this out in the docs might help users, especially those applying builders to existing code.
Thank you for the attention.
The text was updated successfully, but these errors were encountered:
@k-wall: I think that the provided code is problematic and will lead to an NullPointerException in case p2 is actually null. I would suggest to switch the type of p2 property to Integer then both will work as expected.
Sundrio, assumes that properties, constructor arguments and getters match. In some cases we do check for boxing (so this might as well be a bug, but not sure if we do it for all cases). I'll need to check and get back to you.
I'm generating builders for some existing code with POJOs that looks like this:
The generated code fails to compile.
The code gen has omitted to generate a
withP2()
method (or the field) in the fluent, yet the builder implementation assumes it will be present. This suggests an inconsistency in the sundrio implementation.I can imagine to support this use-case, sundrio would need to special casing to use the boxed type in the fluent rather than the primitive. I can well imagine there are gotchas in the detail..
I want to know if this is considered a defect, or an unsupported use-case? If the latter, I wonder if calling this out in the docs might help users, especially those applying builders to existing code.
Thank you for the attention.
The text was updated successfully, but these errors were encountered: