Skip to content

CD generates instantiating build() methods for abstract classes #119

Description

@schmalzing

Issue description

The class-diagram generator creates a builder and a concrete build() method for classes declared as abstract when ${decConfig.withBuilders().defaultApply()} is configured. The generated build() method instantiates the abstract type, causing the generated Java sources to fail compilation.

Abstract CD classes map to Java abstract classes and must not be instantiated directly.

Reproduction

Example CD:

public abstract class MCConcept extends Class {
  boolean top;
}

The same issue occurs for an abstract class such as:

public abstract class Class { }

Actual behavior

The generator creates a builder implementation that contains code equivalent to:

var v = new Class();

This produces a Java compiler error:

ERROR in ...\montiarc\generator\meta\Java\ClassBuilder.java (at line 150)
var v = new Class();
            ^^^^^

The generated builder tries to instantiate Class, although Class is declared abstract.

Expected behavior

For an abstract CD class, the generator must not emit a build() implementation that instantiates that class.

Possible valid generator behavior would be one of:

  • Do not generate a builder for abstract classes.
  • Generate the builder but omit build().
  • Generate an abstract builder and declare build() as abstract.
  • Generate builders only for concrete subclasses, whose build() methods instantiate the respective concrete class.

Impact

Any CD containing an abstract class can produce Java code that does not compile. This prevents use of abstract base classes in generated POJO models and forces users to avoid a standard object-oriented modeling mechanism.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions