Skip to content

IllegalArgumentException in AsciiDoc generation for Spring @EventListeners without parameters #1006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
frademacher opened this issue Dec 26, 2024 · 1 comment
Assignees
Labels
in: documentation support Documentation generation type: bug Something isn't working
Milestone

Comments

@frademacher
Copy link

Hi all,

I'm currently experimenting with Spring Modulith 1.3.1 and found it to be a great initiative towards supporting the transition from Big Balls of Mud into properly structured monoliths. So first of all, thanks a lot for this :-)

However, I'm currently encountering an IllegalArgumentException when trying to generate AsciiDoc diagrams from an experimental codebase that uses a Spring @EventListener method to store initial data into an ephemeral H2 database. The method signature is as follows:

@Component
public class CatalogData {
    ...

    @EventListener(ApplicationStartedEvent.class)
    public void initialData() {
        // Invoke some save() operations in an injected repository
        ...
    }

The above code works flawlessly when running the Spring application. However, when attempting AsciiDoc generation using the following method

class ArchitectureTest {
    ...

    private static final ApplicationModules MODULES = ApplicationModules.of(App.class);
    void generateAsciiDoc() {
        var diagramOpts = Documenter.DiagramOptions.defaults().withStyle(Documenter.DiagramOptions.DiagramStyle.UML);
        var canvasOpts = Documenter.CanvasOptions.defaults();
		new Documenter(MODULES).writeDocumentation(diagramOpts, canvasOpts);
    }
}

I'm getting an IllegalArgumentException stating that

Method JavaMethod{....initialData()} must have at least one parameter!

from

The error is straightforward, and adding a parameter for the caught event and therefore changing the method signature to

    public void initialData(ApplicationStartedEvent event) {

fixes the issue.

Still wanted to report it, because Spring seemingly allows omitting the event parameter, while Spring Modulith seems to expect it.

@odrotbohm odrotbohm self-assigned this Jan 6, 2025
@odrotbohm odrotbohm added this to the 1.4 M1 milestone Jan 6, 2025
@odrotbohm odrotbohm added in: documentation support Documentation generation type: bug Something isn't working labels Jan 6, 2025
odrotbohm added a commit that referenced this issue Jan 6, 2025
…otations.

We now detect event types a listener is interested in declared in annotations for inclusion the reference documentation. This allows for the rare case that the event listener method not actually declaring the event type as parameter as it might not be needed in the payload but only the fact that an event was published at all.
@odrotbohm odrotbohm changed the title IllegalArgumentException in AsciiDoc generation for Spring @EventListeners without parameters IllegalArgumentException in AsciiDoc generation for Spring @EventListeners without parameters Jan 6, 2025
@odrotbohm
Copy link
Member

That's fixed and back-ported. In addition to the fix, we now properly document all event types listed in the annotation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: documentation support Documentation generation type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants