ktuukkan/marine-api

ZDA message getTime() fails when no offset's are present, no matter if time is present or not.

tmaxted opened this issue · 1 comments

When calling getTime() on a zdaSentence, if there are no timezone offsets present the method will return a DataNotAvailableException, even if the time is available.

Stacktrace:
2019/09/05 00:02:10.923 [INFO ] 2 $GPZDA,000212.926501,05,09,2019,,*68 2019/09/05 00:02:10.925 [WARN ] NettyDatagramHandler Exception caught in Datagram handler net.sf.marineapi.nmea.parser.DataNotAvailableException: Data not available at net.sf.marineapi.nmea.parser.SentenceParser.getStringValue(SentenceParser.java:432) at net.sf.marineapi.nmea.parser.SentenceParser.getIntValue(SentenceParser.java:408) at net.sf.marineapi.nmea.parser.ZDAParser.getLocalZoneHours(ZDAParser.java:79) at net.sf.marineapi.nmea.parser.ZDAParser.getTime(ZDAParser.java:97) at [redacted].Application$2.handleData(Application.java:124) at [redacted].handleData(NMEAConnection.java:80) at [redacted]$1.handleDatagram(NMEAConnection.java:70) at [redacted].NettyDatagramHandler.channelRead0(NettyDatagramHandler.java:50) at [redacted].NettyDatagramHandler.channelRead0(NettyDatagramHandler.java:19) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:345) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:337) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1408) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:345) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:930) at io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:93) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:677) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:612) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:529) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:491) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:834)

Code with the method call:
code

I fixed this by creating a local class which extended SentenceParser and implemented ZDASentence. Then altered the getTime() method to have a try catch block around the method calls to the getLocalZone_() methods.

Like so:
code

Or completely ignoring the offsets:
code