hilla icon indicating copy to clipboard operation
hilla copied to clipboard

Multi-module generator fails on `reactor.core.publisher.Flux`

Open cromoteca opened this issue 3 years ago • 3 comments

While searching for the dependencies of public org.reactivestreams.Publisher<V> apply(java.util.List<? extends org.reactivestreams.Publisher<?>>), the generator seems unable to resolve V:

...
Caused by: java.lang.IllegalArgumentException: Could not resolve V against parameters of the defining method or enclosing class
    at io.github.classgraph.TypeVariableSignature.resolve (TypeVariableSignature.java:118)
    at dev.hilla.parser.models.DependencyCollector$Source.collectTypeVariableSignature (DependencyCollector.java:195)
    at dev.hilla.parser.models.DependencyCollector$Source.collect (DependencyCollector.java:151)
    at dev.hilla.parser.models.DependencyCollector$Source.collectTypeArgument (DependencyCollector.java:187)
    at dev.hilla.parser.models.DependencyCollector$Source.collect (DependencyCollector.java:153)
    at dev.hilla.parser.models.DependencyCollector$Source.collectClassRefTypeSignature (DependencyCollector.java:182)
    at dev.hilla.parser.models.DependencyCollector$Source.collect (DependencyCollector.java:155)
    at dev.hilla.parser.models.DependencyCollector.collect (DependencyCollector.java:33)
    at dev.hilla.parser.models.SourceSignatureModel.getDependenciesStream (SourceSignatureModel.java:13)
    at dev.hilla.parser.models.MethodInfoModel.getResultDependenciesStream (MethodInfoModel.java:60)
    at dev.hilla.parser.models.MethodInfoModel.getDependenciesStream (MethodInfoModel.java:33)
    at java.util.stream.ReferencePipeline$7$1.accept (ReferencePipeline.java:271)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining (ArrayList.java:1655)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:484)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:474)
    at java.util.stream.ForEachOps$ForEachOp.evaluateSequential (ForEachOps.java:150)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential (ForEachOps.java:173)
    at java.util.stream.AbstractPipeline.evaluate (AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.forEach (ReferencePipeline.java:497)
    at java.util.stream.ReferencePipeline$7$1.accept (ReferencePipeline.java:274)
    at java.util.Spliterators$ArraySpliterator.forEachRemaining (Spliterators.java:948)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:484)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:474)
    at java.util.stream.ForEachOps$ForEachOp.evaluateSequential (ForEachOps.java:150)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential (ForEachOps.java:173)
    at java.util.stream.AbstractPipeline.evaluate (AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.forEach (ReferencePipeline.java:497)
    at dev.hilla.parser.core.ScanElementsCollector.collect (ScanElementsCollector.java:95)
    at dev.hilla.parser.core.Parser.execute (Parser.java:61)
    at dev.hilla.maven.ParserProcessor.process (ParserProcessor.java:89)
    at dev.hilla.maven.EndpointCodeGeneratorMojo.parseJavaCode (EndpointCodeGeneratorMojo.java:57)
    at dev.hilla.maven.EndpointCodeGeneratorMojo.execute (EndpointCodeGeneratorMojo.java:26)
...

This is the related code from the Flux class:

public static <TUPLE extends Tuple2, V> Flux<V> zip(Publisher<? extends
    Publisher<?>> sources,
    final Function<? super TUPLE, ? extends V> combinator) {

    return onAssembly(new FluxBuffer<>(from(sources), Integer.MAX_VALUE, listSupplier())
        .flatMap(new Function<List<? extends Publisher<?>>, Publisher<V>>() {
            @Override
            public Publisher<V> apply(List<? extends Publisher<?>> publishers) {
                return zip(Tuples.fnAny((Function<Tuple2, V>)
                    combinator), publishers.toArray(new Publisher[publishers
                    .size()]));
            }
        }));
}

I'm using the main branch as it is now (at commit #3866c65). I've run mvn generator:generate on Java 11 and Java 17 and I got the same exception.

cromoteca avatar Jun 29 '22 08:06 cromoteca

It should not interpret Flux as a bean. Flux is a special case and only the type parameter of the Flux should be processed

Artur- avatar Jun 29 '22 08:06 Artur-

It depends on how we want to implement push support in the multi-module generator: while the generated endpoints are supposed to be identical, the differentiation between call and subscribe could happen after OpenAPI generation.

Anyway, this bug is not strictly related to the Flux class and might happen in similar cases.

cromoteca avatar Jun 29 '22 09:06 cromoteca

See #487 for fixing treating Flux as a bean.

platosha avatar Aug 09 '22 12:08 platosha