Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-2985

Mongo DB throwing NullPointerException on find()

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.8.1
    • Component/s: Async, Query Operations
    • None
    • Environment:
      Ubuntu Linux operating system.

      I am retrieving the documents from the MongoDB with the collection.find().into() to generate the documents. The following is the code -

       

      List<Document> scrapingInformation = new LinkedList<>();
      database.getCollection(scrapingInformationByClientidJobid)
       .find(and(eq("clientId", clientId), eq("jobId", jobId)))
       .into(scrapingInformation, (res, ex) ->
      { 
          ex.printStackTrace(); System.out.println("Exception while iterating over the finditerable and adding to document list: " + ex.getMessage()); }
      );
      System.out.println("Total populated documents in list: " + scrapingInformation.size());{{ }}
      

       

      Data is there in the database. The find() method reads that data as well. The problem comes when I try to iterate on the data. I tried iterating over the FindIterable as well. There was also the NullPointerException.

      The version I installed is 4.0 and driver 3.8.1. To remove the possibility of version conflict I downgraded to 3.6.1 and still, there is the problem.

      Following is the stacktrace:

      java.lang.NullPointerException
      	at com.fastscraping.dao.mongo.ScrapingInformationDB.lambda$getScrapingInformation$2(ScrapingInformationDB.java:71)
      	at com.mongodb.async.client.MongoIterableImpl$2$2.onResult(MongoIterableImpl.java:110)
      	at com.mongodb.async.client.MongoIterableImpl$2$2.onResult(MongoIterableImpl.java:104)
      	at com.mongodb.async.client.MongoIterableImpl$4.onResult(MongoIterableImpl.java:171)
      	at com.mongodb.async.client.MongoIterableImpl$4.onResult(MongoIterableImpl.java:166)
      	at com.mongodb.operation.AsyncQueryBatchCursor.next(AsyncQueryBatchCursor.java:141)
      	at com.mongodb.operation.AsyncQueryBatchCursor.next(AsyncQueryBatchCursor.java:100)
      	at com.mongodb.async.client.MongoIterableImpl.loopCursor(MongoIterableImpl.java:166)
      	at com.mongodb.async.client.MongoIterableImpl.access$000(MongoIterableImpl.java:34)
      	at com.mongodb.async.client.MongoIterableImpl$4.onResult(MongoIterableImpl.java:177)
      	at com.mongodb.async.client.MongoIterableImpl$4.onResult(MongoIterableImpl.java:166)
      	at com.mongodb.operation.AsyncQueryBatchCursor.next(AsyncQueryBatchCursor.java:136)
      	at com.mongodb.operation.AsyncQueryBatchCursor.next(AsyncQueryBatchCursor.java:100)
      	at com.mongodb.async.client.MongoIterableImpl.loopCursor(MongoIterableImpl.java:166)
      	at com.mongodb.async.client.MongoIterableImpl.access$000(MongoIterableImpl.java:34)
      	at com.mongodb.async.client.MongoIterableImpl$2.onResult(MongoIterableImpl.java:99)
      	at com.mongodb.async.client.MongoIterableImpl$2.onResult(MongoIterableImpl.java:93)
      	at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
      	at com.mongodb.async.client.OperationExecutorImpl$1$1.onResult(OperationExecutorImpl.java:82)
      	at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
      	at com.mongodb.operation.FindOperation$3.onResult(FindOperation.java:806)
      	at com.mongodb.operation.OperationHelper$ReferenceCountedReleasingWrappedCallback.onResult(OperationHelper.java:364)
      	at com.mongodb.operation.CommandOperationHelper$2.onResult(CommandOperationHelper.java:405)
      	at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
      	at com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor$2.onResult(DefaultServer.java:227)
      	at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
      	at com.mongodb.internal.connection.CommandProtocolImpl$1.onResult(CommandProtocolImpl.java:85)
      	at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection$1.onResult(DefaultConnectionPool.java:461)
      	at com.mongodb.internal.connection.UsageTrackingInternalConnection$2.onResult(UsageTrackingInternalConnection.java:111)
      	at com.mongodb.internal.async.ErrorHandlingResultCallback.onResult(ErrorHandlingResultCallback.java:49)
      	at com.mongodb.internal.connection.InternalStreamConnection$2$1.onResult(InternalStreamConnection.java:379)
      	at com.mongodb.internal.connection.InternalStreamConnection$2$1.onResult(InternalStreamConnection.java:356)
      	at com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback$MessageCallback.onResult(InternalStreamConnection.java:651)
      	at com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback$MessageCallback.onResult(InternalStreamConnection.java:618)
      	at com.mongodb.internal.connection.InternalStreamConnection$5.completed(InternalStreamConnection.java:494)
      	at com.mongodb.internal.connection.InternalStreamConnection$5.completed(InternalStreamConnection.java:491)
      	at com.mongodb.connection.netty.NettyStream.readAsync(NettyStream.java:236)
      	at com.mongodb.internal.connection.InternalStreamConnection.readAsync(InternalStreamConnection.java:491)
      	at com.mongodb.internal.connection.InternalStreamConnection.access$1000(InternalStreamConnection.java:74)
      	at com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback.onResult(InternalStreamConnection.java:608)
      	at com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback.onResult(InternalStreamConnection.java:593)
      	at com.mongodb.internal.connection.InternalStreamConnection$5.completed(InternalStreamConnection.java:494)
      	at com.mongodb.internal.connection.InternalStreamConnection$5.completed(InternalStreamConnection.java:491)
      	at com.mongodb.connection.netty.NettyStream.readAsync(NettyStream.java:236)
      	at com.mongodb.connection.netty.NettyStream.handleReadResponse(NettyStream.java:266)
      	at com.mongodb.connection.netty.NettyStream.access$600(NettyStream.java:66)
      	at com.mongodb.connection.netty.NettyStream$InboundBufferHandler.channelRead0(NettyStream.java:325)
      	at com.mongodb.connection.netty.NettyStream$InboundBufferHandler.channelRead0(NettyStream.java:322)
      	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
      	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
      	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:349)
      	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:341)
      	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334)
      	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
      	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:349)
      	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926)
      	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:129)
      	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:642)
      	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:565)
      	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:479)
      	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:441)
      	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
      	at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
      	at java.lang.Thread.run(Thread.java:748)
      

      What could be the cause of this exception?

            Assignee:
            Unassigned Unassigned
            Reporter:
            ashish1269 Ashish Tomer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: