Skip to content

Code generator silently drops parameters without a name #454

Done

Description

@igel-devin-ai

Problem

RoasterCodeGenerator silently drops a method or constructor parameter that has a type but no name. No exception is thrown, so the generated signature is wrong without any notice.

Reproduction

MethodDto method = new MethodDto();
method.setMethodName("run");
MethodParameterDto parameter = new MethodParameterDto();
parameter.setParameterTypeName(new TypeName("java.lang", "String"));
method.addParameter(parameter);   // DTO now contains one parameter
// render the class containing `method` via RoasterCodeGenerator.generateClass(...)

Expected: void run(String …) or a CodeGenerationException because the parameter name is missing.

Actual: the method renders as

void run() {
}

The same happens for constructors (Target() { }).

Other incomplete DTOs fail loudly: a missing parameter type, field type or annotation type gives a wrapped NPE, and a missing field or method name gives a wrapped IllegalArgumentException. Only the unnamed parameter is skipped silently.

This also happens on main, because MethodParameterDto can be created without a name.

Expected JUnit behaviour

Rendering a method or constructor with an unnamed parameter must throw a CodeGenerationException with a message naming the missing parameter name, instead of omitting the parameter.

Context

Found while reviewing #429. #429 adds a build() check in MethodParameterDtoBuilder, but DTOs created directly still reach the renderer.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions