From 3e5ac12302a78216e706be239dceb5175646bea0 Mon Sep 17 00:00:00 2001 From: Etan Cohen Date: Mon, 18 Jul 2016 10:37:20 -0700 Subject: [PATCH] [NAN] TLV utilities iterator - throw correct exception Make sure that iterator.next() validates that next element exists - otherwise throw the exception specified by the interface. Bug: 30096512 Change-Id: I327da433e3f1181e272c81ee503cbe8aab323f7e --- wifi/java/android/net/wifi/nan/TlvBufferUtils.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wifi/java/android/net/wifi/nan/TlvBufferUtils.java b/wifi/java/android/net/wifi/nan/TlvBufferUtils.java index 8ad9fa3931805..7ce24d543c943 100644 --- a/wifi/java/android/net/wifi/nan/TlvBufferUtils.java +++ b/wifi/java/android/net/wifi/nan/TlvBufferUtils.java @@ -24,6 +24,7 @@ import java.nio.BufferOverflowException; import java.nio.ByteOrder; import java.util.Arrays; import java.util.Iterator; +import java.util.NoSuchElementException; /** * Utility class to construct and parse byte arrays using the TLV format - @@ -464,6 +465,10 @@ public class TlvBufferUtils { @Override public TlvElement next() { + if (!hasNext()) { + throw new NoSuchElementException(); + } + int type = 0; if (mTypeSize == 1) { type = mArray[mOffset];