quarkus: NullPointerException reading mongodb bson date (native image)
Hi,
only native image of my application cause a NullPointerException parsing mongodb document with date field.
The error occours both with quarkus 1.6.0.final and 1.7.0.final.
Here the full staktrace:
2020-08-21 15:12:12,711 ERROR [org.jbo.res.res.i18n] (executor-thread-1) RESTEASY002020: Unhandled asynchronous exception, sending back 500: org.jboss.resteasy.spi.ApplicationException: java.lang.NullPointerException
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:180)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:130)
at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:638)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:504)
at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:454)
at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:456)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:417)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:391)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:68)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:488)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:259)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:160)
at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:163)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:245)
at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:73)
at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:132)
at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.access$000(VertxRequestHandler.java:37)
at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler$1.run(VertxRequestHandler.java:94)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
at java.lang.Thread.run(Thread.java:834)
at org.jboss.threads.JBossThread.run(JBossThread.java:479)
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:517)
at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
Caused by: java.lang.NullPointerException
at java.text.SimpleDateFormat.matchZoneString(SimpleDateFormat.java:1695)
at java.text.SimpleDateFormat.subParseZoneString(SimpleDateFormat.java:1763)
at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:2169)
at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1541)
at org.bson.json.JsonReader.visitISODateTimeConstructor(JsonReader.java:836)
at org.bson.json.JsonReader.readBsonType(JsonReader.java:225)
at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:85)
at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:42)
at org.bson.codecs.BsonDocumentCodec.readValue(BsonDocumentCodec.java:104)
at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:87)
at org.bson.BsonDocument.parse(BsonDocument.java:63)
at io.quarkus.mongodb.panache.runtime.MongoOperations.executeUpdate(MongoOperations.java:619)
at io.quarkus.mongodb.panache.runtime.MongoOperations.update(MongoOperations.java:614)
at it.cineca.model.elaborato.HeartBeat.update(HeartBeat.java)
at it.cineca.manager.HeartBeatManager.aggiornaBattito(HeartBeatManager.java:64)
at it.cineca.manager.HeartBeatManager_ClientProxy.aggiornaBattito(HeartBeatManager_ClientProxy.zig:216)
at it.cineca.web.BeatController.aggiornaBattito(BeatController.java:38)
at java.lang.reflect.Method.invoke(Method.java:566)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167)
... 29 more
I’m compiling native image using maven’s quarkus standard configuration with these Resource Configuration File:
{
"bundles": [ {"name":"sun.util.resources.TimeZoneNames"} ],
"resources": [ { "pattern": "org/joda/time/tz/data/.*/.*$" },
{ "pattern": "org/joda/time/tz/data/.*$" } ]
}
Thank you Nicola
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 41 (29 by maintainers)
Commits related to this issue
- Return when date found in MongoDB's JSonReader #11524 — committed to galderz/quarkus by galderz 4 years ago
- Fine tuning substitution and reflection calls #11524 — committed to galderz/quarkus by galderz 4 years ago
- POC for issue #11524 — committed to jyemin/quarkus by jyemin 4 years ago
- Fix for issue #11524 Replace use of shell syntax for dates with extended JSON syntax — committed to jyemin/quarkus by jyemin 4 years ago
- Fix for issue #11524 Replace use of shell syntax for dates with extended JSON syntax — committed to jyemin/quarkus by jyemin 4 years ago
- Fix for issue #11524 Replace use of shell syntax for dates with extended JSON syntax — committed to jyemin/quarkus by jyemin 4 years ago
- Fix for issue #11524 Replace use of shell syntax for dates with extended JSON syntax — committed to jyemin/quarkus by jyemin 4 years ago
- Fix for issue #11524 Replace use of shell syntax for dates with extended JSON syntax — committed to jyemin/quarkus by jyemin 4 years ago
Hi @nicolinux72, sorry for the confusion. I’m still getting acquainted with Quarkus so I’m getting my bearings.
My misunderstanding stemmed from the sample document you provided, which does indeed use an ISODate format that the driver is not able to parse. But now I see that the ISODate format is something different, and is actually generated by Quarkus itself, right here. This code will generate ISODate strings in the format
yyyy-MM-dd'T'HH:mm:ss.SSS'Z', which is parseable by JsonReader.So I agree that you can’t fix this in your own code, but I think my suggestion could be applied to Quarkus itself: instead of using the shell syntax in CommonQueryBinder, it could use the extended JSON syntax. I created a branch to show the idea: https://github.com/jyemin/quarkus/commit/13154e00db53b9e3b5ff1f0c44b0c89baaf69488.
@galderz does this look like a reasonable avenue to pursue?
@nicolinux72 when I try to parse the example document that you provided:
using the Java driver in OpenJDK, it fails, as the JsonReader throws
org.bson.json.JsonParseException: Invalid date format.Could you try using the Relaxed Extended JSON format instead, which is specified here? The document would like this this:
The method that parses relaxed extended JSON depends on
java.time.format.DateTimeFormatter#ISO_OFFSET_DATE_TIMErather thanSimpleDateFormat, which I think will be immune to the issue you’re encountering. It also correctly parses the date format that you’re using.@loicmathieu I’ll create a substitution and see if @nicolinux72 can try.
We could substitute as a temporal workaround but this issue should be raised on the MongoDB driver as an issue with GraalVM as I think a sample code without quarkus will experiement the same issue.
I’m pretty sure they can use the default TZ instead of EN but they need to do it on their side.
I checked the Graal issue and I don’t think using the workaround based on
@Featureis a good thing to add to Quarkus. You could still add it to your own application as a workaround if needed.I think the best is to raise this to the MongoDB team, for this the best will be to create a minimal reproducer with only the mongodb-driver as dependency (so no Quarkus) to show that the issue here is that MongoDB hardcoded the use of the
enLocale so any attemp to use a different Locale in GraalVM will make the MongoDB ISODate handling broken.