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

NPE in BufferUtils.writeLengthEncode() #78

Open
mdeso opened this issue Apr 16, 2024 · 0 comments · May be fixed by #79
Open

NPE in BufferUtils.writeLengthEncode() #78

mdeso opened this issue Apr 16, 2024 · 0 comments · May be fixed by #79

Comments

@mdeso
Copy link

mdeso commented Apr 16, 2024

When starting a Micronaut 4 application I get an NPE from within BufferUtils.writeLlengthEncode():

Caused by: java.lang.NullPointerException: Cannot invoke "String.getBytes(java.nio.charset.Charset)" because "val" is null
        at org.mariadb.r2dbc.util.BufferUtils.writeLengthEncode(BufferUtils.java:103)
        at org.mariadb.r2dbc.message.client.HandshakeResponse.writeConnectAttributes(HandshakeResponse.java:168)
        at org.mariadb.r2dbc.message.client.HandshakeResponse.encode(HandshakeResponse.java:143)
        at org.mariadb.r2dbc.client.MariadbPacketEncoder.encodeFlux(MariadbPacketEncoder.java:20)
        at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:113)

The causing line is

BufferUtils.writeLengthEncode(properties.getProperty("version"), buf);

The code there seems strange to me. It tries to read a file project.properties, as it seems from anywhere on the classpath. If that file isn't found it silently "eats" the signalling IOException. But if it is found it tries to read the version property from it and write it to the buffer as _client_version. And if the version property doesn't exist this causes the NPE. I would say this read-properties block should be removed completely, it makes no sense as it is completely optional. In my case it found a project.properties in some dependency which didn't contain the expected property, causing the NPE.

A workaround is to place a dummy "project.properties" with a version property in the classpath before any other potential candidate (which may be difficult under certain circumstances).

@mdeso mdeso linked a pull request Apr 16, 2024 that will close this issue
@mdeso mdeso changed the title NPE in BufferUtils.writeLlengthEncode() NPE in BufferUtils.writeLengthEncode() Apr 16, 2024
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

Successfully merging a pull request may close this issue.

1 participant