Skip to content
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

injecting Instance<S3Client> results in NPE at io.quarkus.amazon.s3.runtime.S3ClientProducer.client() #15213

Closed
vladykin opened this issue Feb 20, 2021 · 4 comments · Fixed by #17836
Assignees
Labels
area/amazon-services kind/bug Something isn't working
Milestone

Comments

@vladykin
Copy link

Describe the bug
Attempt to call any S3Client method on instance injected as

  @Inject
  Instance<S3Client> s3ClientInstance;

results in NPE:

java.lang.NullPointerException
	at io.quarkus.amazon.s3.runtime.S3ClientProducer.client(S3ClientProducer.java:23)
	at io.quarkus.amazon.s3.runtime.S3ClientProducer_ProducerMethod_client_c3e44358d8bba829ee2f6ae63d6f9ef0b4609f3a_Bean.create(S3ClientProducer_ProducerMethod_client_c3e44358d8bba829ee2f6ae63d6f9ef0b4609f3a_Bean.zig:202)
	at io.quarkus.amazon.s3.runtime.S3ClientProducer_ProducerMethod_client_c3e44358d8bba829ee2f6ae63d6f9ef0b4609f3a_Bean.create(S3ClientProducer_ProducerMethod_client_c3e44358d8bba829ee2f6ae63d6f9ef0b4609f3a_Bean.zig:233)
	at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:96)
	at io.quarkus.arc.impl.AbstractSharedContext.access$000(AbstractSharedContext.java:14)
	at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:29)
	at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:26)
	at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:26)
	at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
	at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:26)
	at io.quarkus.arc.impl.ClientProxies.getApplicationScopedDelegate(ClientProxies.java:17)
	at io.quarkus.amazon.s3.runtime.S3ClientProducer_ProducerMethod_client_c3e44358d8bba829ee2f6ae63d6f9ef0b4609f3a_ClientProxy.arc$delegate(S3ClientProducer_ProducerMethod_client_c3e44358d8bba829ee2f6ae63d6f9ef0b4609f3a_ClientProxy.zig:86)
	at io.quarkus.amazon.s3.runtime.S3ClientProducer_ProducerMethod_client_c3e44358d8bba829ee2f6ae63d6f9ef0b4609f3a_ClientProxy.createBucket(S3ClientProducer_ProducerMethod_client_c3e44358d8bba829ee2f6ae63d6f9ef0b4609f3a_ClientProxy.zig:2153)
	at S3ClientHolder.doSomethingIndirectly(S3ClientHolder.java:21)

S3Client injected directly as

@Inject
S3Client s3Client;

works without such NPE.

Expected behavior
Instance injected as

@Inject
Instance<S3Client> s3ClientInstance;

should work.

Actual behavior
Currently it throws NPE.

To Reproduce

Application bean:

import software.amazon.awssdk.services.s3.S3Client;

import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class S3ClientHolder {

  @Inject
  Instance<S3Client> s3ClientInstance;

  public void doSomethingIndirectly() {
    s3ClientInstance.get().createBucket(b -> b.bucket("foobar"));
  }
}

Test:

import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;

import javax.inject.Inject;

@QuarkusTest
public class ReproducerTest {

  @Inject
  S3ClientHolder bean;

  @Test
  void indirect_test() {
    bean.doSomethingIndirectly();
  }
}

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>reproducer</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <quarkus.version>1.11.3.Final</quarkus.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-maven-plugin</artifactId>
                <version>${quarkus.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-bom</artifactId>
                <version>${quarkus.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-amazon-s3</artifactId>
        </dependency>
        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>url-connection-client</artifactId>
        </dependency>
        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>netty-nio-client</artifactId>
        </dependency>

        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-junit5</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

Steps to reproduce the behavior:

  1. Create project containing files shown above
  2. mvn clean verify

Configuration

quarkus.s3.aws.region=us-west-2
quarkus.s3.aws.credentials.type=static
quarkus.s3.aws.credentials.static-provider.access-key-id=test
quarkus.s3.aws.credentials.static-provider.secret-access-key=test

Environment (please complete the following information):

  • Output of uname -a: Linux 5.4.48-gentoo #2 SMP Wed Oct 7 20:15:36 MSK 2020 x86_64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz GenuineIntel GNU/Linux
  • Output of java -version: openjdk version "11.0.9.1" 2020-11-04 LTS
  • Quarkus version or git rev: 1.11.3.Final
  • Build tool (output of mvnw --version): Apache Maven 3.6.3
@vladykin vladykin added the kind/bug Something isn't working label Feb 20, 2021
@gsmet gsmet self-assigned this Mar 2, 2021
@gsmet
Copy link
Member

gsmet commented Mar 2, 2021

Yeah, I confirm we can have this type of issues with the current setup. Probably worth some cleanup.

Thanks for the report!

@arvid-villen-adtoox
Copy link

Any updates on this?

@gsmet
Copy link
Member

gsmet commented May 7, 2021

No I didn't have time to look at it. Things need to be rearchitected to use synthetic build items.

@gsmet
Copy link
Member

gsmet commented Jun 10, 2021

Fix is coming in #17836 . Sorry about the delay.

gsmet added a commit to gsmet/quarkus that referenced this issue Jun 10, 2021
@quarkus-bot quarkus-bot bot added this to the 2.1 - main milestone Jun 10, 2021
@gsmet gsmet modified the milestones: 2.1 - main, 2.0.0.Final Jun 21, 2021
gsmet added a commit to gsmet/quarkus that referenced this issue Jun 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/amazon-services kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants