Make OffsetMap enforce access limit 51/22151/2
authorRobert Varga <rovarga@cisco.com>
Mon, 8 Jun 2015 19:08:31 +0000 (21:08 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 9 Jun 2015 08:54:14 +0000 (08:54 +0000)
getValue()/setValue() should ensure that the offset used is covered by
associated routerIds. Also fixes wrong format strings.

Change-Id: I4fafea959bc550e0bf9a2ec048c35ae63c255235
Signed-off-by: Robert Varga <rovarga@cisco.com>
(cherry picked from commit 314664ba879180383f7b70d9b51906cdfa194aa3)

bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/OffsetMap.java

index ff59078178278ba4cd26e306fc3f599c97279c8c..9f7710d2e76379a0e81d63f4eef12d1d9d504ddf 100644 (file)
@@ -76,12 +76,14 @@ final class OffsetMap {
     }
 
     <T> T getValue(final T[] array, final int offset) {
-        Preconditions.checkArgument(offset >= 0, "Invalid negative offset {}", offset);
+        Preconditions.checkArgument(offset >= 0, "Invalid negative offset %s", offset);
+        Preconditions.checkArgument(offset < routerIds.length, "Invalid offset %s for %s router IDs", offset, routerIds.length);
         return array[offset];
     }
 
     <T> void setValue(final T[] array, final int offset, final T value) {
-        Preconditions.checkArgument(offset >= 0, "Invalid negative offset {}", offset);
+        Preconditions.checkArgument(offset >= 0, "Invalid negative offset %s", offset);
+        Preconditions.checkArgument(offset < routerIds.length, "Invalid offset %s for %s router IDs", offset, routerIds.length);
         array[offset] = value;
     }