Results 1 to 6 of 6

Thread: MongoDB geonear null pointer exception

  1. #1
    Join Date
    Jun 2009
    Location
    Singapore
    Posts
    57

    Exclamation MongoDB geonear null pointer exception

    Hi,
    I trying to use geoNear query as per documentation but i am getting null pointer exception . Please guide me any one have any clue about that.
    But when i given data as per Test data "-73.99408, 40.75057" then it will return the data .
    I believe some issue with precision . I took above data from google map.
    following are my code .
    Code:
    Point location = new Point(  1.4377786502730732,103.78692984580994);
            //System.out.println(location.getX() + " " +location.getY());
    //NearQuery query = NearQuery.near(location).maxDistance(new Distance(10, Metrics.MILES));
    NearQuery geoNear = NearQuery.near(location, Metrics.KILOMETERS).num(100000).maxDistance(150);
            GeoResults<LocationMap> loc=null;
            
             loc= mongoTemplate.geoNear(geoNear, LocationMap.class, "map");
            
           
            
    
        return loc;
            
           
            
    
        return loc;
    following are my errors
    java.lang.NullPointerException
    at org.springframework.data.mongodb.core.MongoTemplat e.geoNear(MongoTemplate.java:495)
    at edu.samples.repository.ContactRepository.getneares tLocation(ContactRepository.java:101)
    at edu.samples.repository.ContactRepository$$FastClas sByCGLIB$$eb127cc3.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy. java:191)
    at org.springframework.aop.framework.Cglib2AopProxy$C glibMethodInvocation.invokeJoinpoint(Cglib2AopProx y.java:688)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :150)
    at org.springframework.dao.support.PersistenceExcepti onTranslationInterceptor.invoke(PersistenceExcepti onTranslationInterceptor.java:155)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172)
    at org.springframework.aop.framework.Cglib2AopProxy$D ynamicAdvisedInterceptor.intercept(Cglib2AopProxy. java:621)
    at edu.samples.repository.ContactRepository$$Enhancer ByCGLIB$$523fc494.getnearestLocation(<generated>)
    at edu.samples.mvc.basic.MapNearBy.getCreateForm(MapN earBy.java:39)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.web.bind.annotation.support.Ha ndlerMethodInvoker.invokeHandlerMethod(HandlerMeth odInvoker.java:176)
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.invokeHandlerMethod(An notationMethodHandlerAdapter.java:426)
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.handle(AnnotationMetho dHandlerAdapter.java:414)
    at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:790)
    at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:719)
    at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:644)
    at org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:549)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:621)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:210)
    at org.springframework.web.filter.CharacterEncodingFi lter.doFilterInternal(CharacterEncodingFilter.java :88)
    at org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:210)
    at org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:393)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBas e.invoke(AuthenticatorBase.java:462)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(A ccessLogValve.java:563)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:399)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:317)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:204)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:182)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProce ssor.run(JIoEndpoint.java:311)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
    But in mongodb consol return values .
    [QUOTEdb.runCommand({geoNear : "map", near : [ 1.4377786502730732,103.78692984580994], num : 10,maxDistance:1});

    {
    "ns" : "demo.map",
    "near" : "1101000001000011010100000111001111011011101100110 110",
    "results" : [
    {
    "dis" : 0,
    "obj" : {
    "_id" : ObjectId("4eda473a81c645720ea7b19f"),
    "_class" : "edu.samples.mvc.basic.LocationMap",
    "name" : "Test",
    "businessName" : "te",
    "type" : "test",
    "location" : [
    1.4377786502730732,
    103.78692984580994
    ]
    }
    },
    {
    "dis" : 0.0013569590379217517,
    "obj" : {
    "_id" : ObjectId("4eda46e581c645720ea7b19e"),
    "_class" : "edu.samples.mvc.basic.LocationMap",
    "name" : "woodlands",
    "businessName" : "test",
    "type" : "test",
    "location" : [
    1.4367811824404524,
    103.78600984811783
    ]
    }
    },
    {
    "dis" : 0.06732367409178631,
    "obj" : {
    "_id" : ObjectId("4eda330581c637cdd8c4230e"),
    "_class" : "edu.samples.mvc.basic.LocationMap",
    "name" : "Choa Chu kang",
    "businessName" : "choa ",
    "type" : "rest",
    "location" : [
    1.385108,
    103.744998
    ]
    }
    }
    ],
    "stats" : {
    "time" : 0,
    "btreelocs" : 0,
    "nscanned" : 4,
    "objectsLoaded" : 3,
    "avgDistance" : 0.022893544376569357,
    "maxDistance" : 0.0673435230737175
    },
    "ok" : 1
    }
    > db.runCommand({geoNear : "map", near : [ 1.4377786502730732,103.78692984580994], num : 10,maxDistance:1});
    {
    "ns" : "demo.map",
    "near" : "1101000001000011010100000111001111011011101100110 110",
    "results" : [
    {
    "dis" : 0,
    "obj" : {
    "_id" : ObjectId("4eda473a81c645720ea7b19f"),
    "_class" : "edu.samples.mvc.basic.LocationMap",
    "name" : "Test",
    "businessName" : "te",
    "type" : "test",
    "location" : [
    1.4377786502730732,
    103.78692984580994
    ]
    }
    },
    {
    "dis" : 0.0013569590379217517,
    "obj" : {
    "_id" : ObjectId("4eda46e581c645720ea7b19e"),
    "_class" : "edu.samples.mvc.basic.LocationMap",
    "name" : "woodlands",
    "businessName" : "test",
    "type" : "test",
    "location" : [
    1.4367811824404524,
    103.78600984811783
    ]
    }
    },
    {
    "dis" : 0.06732367409178631,
    "obj" : {
    "_id" : ObjectId("4eda330581c637cdd8c4230e"),
    "_class" : "edu.samples.mvc.basic.LocationMap",
    "name" : "Choa Chu kang",
    "businessName" : "choa ",
    "type" : "rest",
    "location" : [
    1.385108,
    103.744998
    ]
    }
    }
    ],
    "stats" : {
    "time" : 0,
    "btreelocs" : 0,
    "nscanned" : 4,
    "objectsLoaded" : 3,
    "avgDistance" : 0.022893544376569357,
    "maxDistance" : 0.0673435230737175
    },
    "ok" : 1
    }

    [/QUOTE]
    Last edited by sony_notes; Dec 3rd, 2011 at 09:27 PM.

  2. #2
    Join Date
    Jun 2009
    Location
    Singapore
    Posts
    57

    Default

    But when i run dbcommand using mongo db api . its returning results .I already submitted bug report in jira too .

    Code:
    DBObject cmd = null;; 
    BasicDBObjectBuilder documentBuilder = BasicDBObjectBuilder.start().add("geoNear", "map").add("near", new
    double[] {1.4377786502730732,103.78692984580994}).add("num", 10).add("maxDistance", 10);
    cmd = documentBuilder.get();
    CommandResult cr =db.command(cmd);
    System.out.println(cr.getErrorMessage());
    System.out.println( cr.toString());

  3. #3
    Join Date
    Jun 2009
    Location
    Singapore
    Posts
    57

    Default

    Finally i got a solution to find geoNear query for mongodb .
    http://sjohn4.wordpress.com/2011/12/...spatial-query/

  4. #4
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    For some reason you seem to pipe in null to MongoTemplate.geoNear(…). I've created a ticket [0] to reject nulls more explicitly as required by MongoOperations and fixed it [1] already. Snapshot is deployed so feel free to see if you get the InvalidDataAccessApiUsageException now which would indicate your argument being null.

    [0] https://jira.springsource.org/browse/DATAMONGO-341
    [1] https://github.com/SpringSource/spri...7611e4971b90f1

  5. #5
    Join Date
    Jun 2009
    Location
    Singapore
    Posts
    57

    Default

    Hi Oliver,
    Thanks for reply .
    When i run following code its getting null pointer exception before . Now i believe i get InvalidDataAccessApiUsageException.
    But as per below code never geoNear is null .
    HTML Code:
    NearQuery geoNear = NearQuery.near(location, Metrics.KILOMETERS).num(100000).maxDistance(150);
            GeoResults<LocationMap> loc=null;
            
             loc= mongoTemplate.geoNear(geoNear, LocationMap.class, "map");
    But same query i try to do with dbcommand it will works as expected .
    Regrds
    Sony

  6. #6
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    Would you mind coming up with a test case and attach that to the ticket you created? I've validated maxDistance(…) to return a not-null value so there's got to be some code in between the two lines you posted that null the geoNear instance. Let's work things out at the ticket as we create two streams of information otherwise, thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •