Issue description
The class-diagram generator creates builders for all classes when ${decConfig.withBuilders().defaultApply()} is configured. For subclasses, the generated builder also initializes attributes inherited from the superclass.
However, when an inherited attribute is declared private, the generated subclass builder accesses it directly. Since private Java fields cannot be accessed from a subclass, the generated Java sources fail compilation.
Reproduction
Example CD:
classdiagram CD {
public class A {
private String name;
}
public class B extends A { }
}
Generate the Java code with:
${decConfig.withBuilders().defaultApply()}
Actual behavior
The generator creates BBuilder and emits code equivalent to:
var v = new B();
v.name = this.name;
This produces a Java compiler error:
ERROR in ...\test\CD\BBuilder.java (at line 104)
v.name = this.name;
^^^^
The field A.name is not visible
The generated BBuilder tries to directly initialize name, although the attribute is declared as private in superclass A.
Expected behavior
The generated builder for a subclass must not directly access private attributes declared in a superclass.
Possible valid generator behavior would be one of:
- Initialize inherited attributes through an accessible constructor, setter, or other method declared by the superclass.
- Delegate initialization of inherited attributes to the superclass builder.
- Exclude private inherited attributes from the subclass builder.
Impact
Any CD containing a subclass whose superclass declares private attributes can produce Java code that does not compile when builders are enabled. This prevents the use of encapsulated attributes together with inheritance in generated POJO models.
Issue description
The class-diagram generator creates builders for all classes when
${decConfig.withBuilders().defaultApply()}is configured. For subclasses, the generated builder also initializes attributes inherited from the superclass.However, when an inherited attribute is declared
private, the generated subclass builder accesses it directly. Since private Java fields cannot be accessed from a subclass, the generated Java sources fail compilation.Reproduction
Example CD:
Generate the Java code with:
${decConfig.withBuilders().defaultApply()}Actual behavior
The generator creates
BBuilderand emits code equivalent to:This produces a Java compiler error:
The generated
BBuildertries to directly initializename, although the attribute is declared asprivatein superclassA.Expected behavior
The generated builder for a subclass must not directly access private attributes declared in a superclass.
Possible valid generator behavior would be one of:
Impact
Any CD containing a subclass whose superclass declares private attributes can produce Java code that does not compile when builders are enabled. This prevents the use of encapsulated attributes together with inheritance in generated POJO models.