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

apicurio.registry.headers.enabled=false causes NullPointerException #2663

Closed
merlor opened this issue Aug 1, 2022 · 2 comments
Closed

apicurio.registry.headers.enabled=false causes NullPointerException #2663

merlor opened this issue Aug 1, 2022 · 2 comments

Comments

@merlor
Copy link

merlor commented Aug 1, 2022

I'm using apicurio 2.2.5.Final with spring cloud stream kafka streams and avroSerdes, I have to read/write the artifact identifier from/to payload instead of headers so I have added this configuration to my props file:

spring.cloud.stream.kafka.streams.binder.configuration.apicurio.registry.headers.enabled=false

But after this addition every message received cause:

java.lang.NullPointerException: Cannot invoke "io.apicurio.registry.serde.headers.HeadersHandler.readHeaders(org.apache.kafka.common.header.Headers)" because "this.headersHandler" is null

The problem is in the method deserialize(String topic, Headers headers, byte[] data) inside the class io.apicurio.registry.serde.AbstractKafkaDeserializer; this is the code:

    public U deserialize(String topic, Headers headers, byte[] data) {
        if (data == null) {
            return null;
        }
        ArtifactReference artifactReference = null;
        if (headers != null) {                                            <-- headers isn't null, It's an object with an empty array
            artifactReference = headersHandler.readHeaders(headers);      <-- headersHandler is null and causes the NPE

            if (artifactReference.hasValue()) {
                return readData(topic, headers, data, artifactReference);
            }
        }
        if (data[0] == MAGIC_BYTE) {
            return deserialize(topic, data);
        } else if (headers == null){
            throw new IllegalStateException("Headers cannot be null");
        } else {
            //try to read data even if artifactReference has no value, maybe there is a fallbackArtifactProvider configured
            return readData(topic, headers, data, artifactReference);
        }
    }

There is no headers in the message but the condition (headers != null) is true (because the variable is valorized with an empty array) and the call headersHandler.readHeaders(headers) with headersHandler null causes a NPE.

Am I doing all right or there are other configurations to add?

A possible solution could be change headers != null into headers != null && headers.toArray().size() > 0 or check if headersHandler is not null

@ajborley
Copy link
Contributor

ajborley commented Aug 1, 2022

I think this is the same as #2641 and should be fixed in the next release via this PR: #2642

@merlor
Copy link
Author

merlor commented Aug 3, 2022

@ajborley It's exactly the same issue (my bad, I didn't see it). You can close, thank you so much for the fast response.

@jsenko jsenko closed this as completed Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants