USACE / cwms-data-api

Corps Water Management System RESTful Data Service
MIT License
13 stars 14 forks source link

NullPointerException on locations/getOne #242

Closed adamkorynta closed 1 year ago

adamkorynta commented 2 years ago

This looks to be caused by the location not having a latitude or longitude defined.

WARNING: error on request[3265172488463210934]: /cwms-data/locations/Abington
java.lang.NullPointerException
    at cwms.radar.data.dao.LocationsDaoImpl.buildLocation(LocationsDaoImpl.java:86)
    at cwms.radar.data.dao.LocationsDaoImpl.getLocation(LocationsDaoImpl.java:73)
    at cwms.radar.api.LocationController.getOne(LocationController.java:223)
    at io.javalin.apibuilder.CrudFunction$2.invoke$lambda-0(CrudHandler.kt:31)
    at io.javalin.apibuilder.CrudFunctionHandler.handle(CrudHandler.kt)
    at cwms.radar.security.CwmsAccessManager.manage(CwmsAccessManager.java:42)
    at io.javalin.http.JavalinServlet.addHandler$lambda-0(JavalinServlet.kt:96)
    at io.javalin.http.JavalinServlet$lifecycle$2$1$1.invoke(JavalinServlet.kt:43)
    at io.javalin.http.JavalinServlet$lifecycle$2$1$1.invoke(JavalinServlet.kt:43)
    at io.javalin.http.JavalinServletHandler.executeNextTask(JavalinServletHandler.kt:99)
    at io.javalin.http.JavalinServletHandler.queueNextTaskOrFinish$lambda-1(JavalinServletHandler.kt:85)
    at java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:995)
    at java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2137)
    at io.javalin.http.JavalinServletHandler.queueNextTaskOrFinish$javalin(JavalinServletHandler.kt:85)
    at io.javalin.http.JavalinServletHandler.executeNextTask$lambda-11$lambda-10(JavalinServletHandler.kt:119)
    at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:616)
    at java.util.concurrent.CompletableFuture.uniApplyStage(CompletableFuture.java:628)
    at java.util.concurrent.CompletableFuture.thenApply(CompletableFuture.java:1996)
    at io.javalin.http.JavalinServletHandler.executeNextTask(JavalinServletHandler.kt:119)
    at io.javalin.http.JavalinServletHandler.queueNextTaskOrFinish$lambda-1(JavalinServletHandler.kt:85)
    at java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:995)
    at java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2137)
    at io.javalin.http.JavalinServletHandler.queueNextTaskOrFinish$javalin(JavalinServletHandler.kt:85)
    at io.javalin.http.JavalinServlet.service(JavalinServlet.kt:89)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
    at cwms.radar.ApiServlet.service(ApiServlet.java:339)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1787)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
    at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:750)
rma-rripken commented 2 years ago

It looks like Location.Builder is coded such that latitude and longitude are double, not Double and although the setters can take a Double they npe if that Double is null.
The error above indicates that the database must have rows with null lat/lon. Maybe this was just a bad assumption by the initial author? Its an easy fix to change the fields from double->Double and to remove the null checks. IMO maybe 20 minutes of actual work.

MikeNeilson commented 2 years ago

Yeah, if I remember right our new standard is "dude, we need the lat/long." but there's a lot of old data.

Would it be reason to include the check on POST only?

rma-rripken commented 2 years ago

Requiring it on POST seems valid.