Quarkus: @Produces annotated methods that are not consumed not ignored and result in failed build

Created on 16 Sep 2019  路  4Comments  路  Source: quarkusio/quarkus

Describe the bug
Issue described here persists under 0.20.0.

Expected behavior
When using a class with method annotated with @Produces, even if never "produced", expect successful build.

Actual behavior
Build fails with misleading error message:

[ERROR] Failed to execute goal io.quarkus:quarkus-maven-plugin:0.20.0:build (default) on project injector-jira-service: Failed to build a runnable JAR: Failed to build a runner jar: Failed to augment application classes: Build failure: Build failed due to errors
[ERROR]     [error]: Build step io.quarkus.arc.deployment.ArcProcessor#generateResources threw an exception: java.lang.IllegalArgumentException: Must be a Class or String, got null
[ERROR] -> [Help 1]
[ERROR]

To Reproduce
Steps to reproduce the behavior:

Simple reproducer:

package service;

@ApplicationScoped
public class SomeResource {
    @Inject
    SomeService someService;

    public void doSomething() {
    }
}
package service;

import client.SomeProvider;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;

@ApplicationScoped
public class SomeService {
    @Inject
    @RequestScoped
    SomeProvider someProvider;

    //  as a workaround, the "produced" but unused bean can be instantiated but ignored to silence this error
    // @Inject
    // @RequestScoped
    // SomeClient someClient;

    public void doSomething() {
    }
}
package client;

import java.net.URI;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import org.eclipse.microprofile.rest.client.RestClientBuilder;

@RequestScoped
public class SomeProvider {

    @Produces
    @RequestScoped
    public SomeClient getClient() {
        return RestClientBuilder
                .newBuilder()
                .baseUri(URI.create("http://example.com"))
                .build(SomeClient.class);
    }
}
package com.cloudbees.sdm.injector.jira.client;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Consumes("application/json")
@Produces("application/json")
public interface SomeClient {

    @GET
    @Path("/rest/api/lols")
    void getLols();
}

Add classes to project and build with maven.

Configuration
N/A

Environment (please complete the following information):

  • Output of uname -a or ver:
$ uname -a
Darwin ip-192-168-1-137.ec2.internal 18.2.0 Darwin Kernel Version 18.2.0: Mon Nov 12 20:24:46 PST 2018; root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64
  • Output of java -version:
$ java -version
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit GraalVM EE 19.1.1 (build 25.221-b11-jvmci-19.1-b01, mixed mode)
  • Quarkus version or git rev: 0.20.0
arearc kinbug

All 4 comments

Hi, just a quick question, have you tried with the latest Quarkus 0.22.0?

Hm, but SomeClient is proxyable.... I'll try to reproduce the issue and we'll see what the real problem is.

By the way, an injection point (e.g. SomeService#someProvider) should not declare a scope annotation -> it will be simply ignored.

It turns out we have a bug in the bean removal algorithm. If there's a bean that declares an unused producer we remove the declaraing bean although it's injected somewhere.

Was this page helpful?
0 / 5 - 0 ratings