SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
805 stars 171 forks source link

java.lang.NullPointerException when using XHR request #200

Closed cyf992002 closed 7 years ago

cyf992002 commented 7 years ago

When I use XMLHttpRequest object to request http://a:a@15.19.249.25:8080/db/_schemas/Organization, I sometimes get NullPointerException in the response. { "_exceptions": [ { "exception": "java.lang.NullPointerException" } ], "http status code": 500, "http status description": "Internal Server Error", "message": "Error handling the request, see log for more information" }

Here's log I captured java.lang.NullPointerException: null at org.restheart.handlers.schema.JsonSchemaTransformer.unescapeSchema(JsonSchemaTransformer.java:160) at org.restheart.handlers.schema.JsonSchemaTransformer.transform(JsonSchemaTransformer.java:57) at org.restheart.handlers.metadata.TransformerHandler.lambda$transform$0(TransformerHandler.java:93) at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) at java.util.stream.ReferencePipeline$Head.forEachOrdered(ReferencePipeline.java:590) at org.restheart.handlers.metadata.TransformerHandler.transform(TransformerHandler.java:92) at org.restheart.handlers.metadata.TransformerHandler.handleRequest(TransformerHandler.java:69) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:136) at org.restheart.handlers.document.GetDocumentHandler.handleRequest(GetDocumentHandler.java:170) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:136) at org.restheart.handlers.metadata.AbstractTransformerMetadataHandler.handleRequest(AbstractTransformerMetadataHandler.java:63) at org.restheart.handlers.RequestDispacherHandler.handleRequest(RequestDispacherHandler.java:468) at org.restheart.handlers.injectors.CollectionPropsInjectorHandler.handleRequest(CollectionPropsInjectorHandler.java:98) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:136) at org.restheart.handlers.injectors.DbPropsInjectorHandler.handleRequest(DbPropsInjectorHandler.java:92) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:136) at org.restheart.handlers.injectors.AccountInjectorHandler.handleRequest(AccountInjectorHandler.java:56) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:136) at org.restheart.security.handlers.AccessManagerHandler.handleRequest(AccessManagerHandler.java:55) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:136) at org.restheart.security.handlers.AuthTokenInjecterHandler.handleRequest(AuthTokenInjecterHandler.java:70) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:136) at org.restheart.security.handlers.AuthenticationCallHandler.handleRequest(AuthenticationCallHandler.java:54) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:136) at org.restheart.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:55) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:136) at org.restheart.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:61) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:136) at org.restheart.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:85) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:136) at org.restheart.security.handlers.SecurityHandler.handleRequest(SecurityHandler.java:50) at org.restheart.security.handlers.SecurityHandlerDispacher.handleRequest(SecurityHandlerDispacher.java:60) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:136) at org.restheart.handlers.injectors.BodyInjectorHandler.handleRequest(BodyInjectorHandler.java:109) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:136) at org.restheart.handlers.OptionsHandler.handleRequest(OptionsHandler.java:58) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:136) at org.restheart.handlers.injectors.RequestContextInjectorHandler.handleRequest(RequestContextInjectorHandler.java:647) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:136) at org.restheart.security.handlers.CORSHandler.handleRequest(CORSHandler.java:88) at org.restheart.handlers.RequestLoggerHandler.handleRequest(RequestLoggerHandler.java:87) at org.restheart.handlers.PipedHttpHandler.handleRequest(PipedHttpHandler.java:89) at io.undertow.server.handlers.PathHandler.handleRequest(PathHandler.java:94) at io.undertow.server.handlers.HttpContinueAcceptingHandler.handleRequest(HttpContinueAcceptingHandler.java:78) at org.restheart.handlers.ErrorHandler.handleRequest(ErrorHandler.java:69) at io.undertow.server.handlers.encoding.EncodingHandler.handleRequest(EncodingHandler.java:72) at org.restheart.handlers.GzipEncodingHandler.handleRequest(GzipEncodingHandler.java:74) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:210) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:809) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

ujibang commented 7 years ago

yep this is a known bug fixed in 3.1.0-SNAPSHOT

can you try with latest release?

mkjsix commented 7 years ago

@ujibang shall we try to issue a 3.0.2 with a fix for this or we'll leave it to a 3.1.0 only?

cyf992002 commented 7 years ago

@ujibang Thanks for your response, I tried 3.1.0-SNAPSHOT just now, same error.

mkjsix commented 7 years ago

@ujibang the commit is tiny, I think I'll cherry-pick it into the 3.0.x branch and release a 3.0.2 stable

ujibang commented 7 years ago

ok I have added a check to avoid the NullPointerException

can you try with latest SNAPSHOT? hit get it from sonatype

cyf992002 commented 7 years ago

Thanks @ujibang, I can see it has been fixed, but a new issue comes up, when I try to post a request with following url http://a:a@15.19.249.25:8080/db/Organization to create a record, I got following error: Response: { "_warnings": "error applying checker: wrong configuration for metadata-named-singletons; interface class org.restheart.hal.metadata.singletons.Checker not found" "http status code": 400 "http status description": "Bad Request" "message": "request check failed" } but it works ok on 3.0.1 release

ujibang commented 7 years ago

Yep we reactors packages in 3.1 so you need to update the configuration file where checkers, transformers and hooks are defined. Here the class names are changed

cyf992002 commented 7 years ago

Close issue, thanks everyone.