Yuta HIGUCHI
Committed by Gerrit Code Review

NPE fix for ONOS-379

Change-Id: If9f68de9355ac3c0154935f61be3322752cfd8ea
...@@ -355,7 +355,16 @@ public class HazelcastLinkResourceStore ...@@ -355,7 +355,16 @@ public class HazelcastLinkResourceStore
355 // all requests allocatable => add allocation 355 // all requests allocatable => add allocation
356 final LinkKey linkKey = LinkKey.linkKey(link); 356 final LinkKey linkKey = LinkKey.linkKey(link);
357 STxMap<LinkKey, List<LinkResourceAllocations>> linkAllocs = getLinkAllocs(tx); 357 STxMap<LinkKey, List<LinkResourceAllocations>> linkAllocs = getLinkAllocs(tx);
358 - final List<LinkResourceAllocations> before = linkAllocs.get(linkKey); 358 + List<LinkResourceAllocations> before = linkAllocs.get(linkKey);
359 + if (before == null) {
360 + List<LinkResourceAllocations> after = new ArrayList<>();
361 + after.add(allocations);
362 + before = linkAllocs.putIfAbsent(linkKey, after);
363 + if (before != null) {
364 + // concurrent allocation detected, retry transaction
365 + throw new TransactionException("Concurrent Allocation, retry");
366 + }
367 + }
359 List<LinkResourceAllocations> after = new ArrayList<>(before.size() + 1); 368 List<LinkResourceAllocations> after = new ArrayList<>(before.size() + 1);
360 after.addAll(before); 369 after.addAll(before);
361 after.add(allocations); 370 after.add(allocations);
...@@ -480,7 +489,7 @@ public class HazelcastLinkResourceStore ...@@ -480,7 +489,7 @@ public class HazelcastLinkResourceStore
480 List<LinkResourceAllocations> res = null; 489 List<LinkResourceAllocations> res = null;
481 res = linkAllocs.get(key); 490 res = linkAllocs.get(key);
482 if (res == null) { 491 if (res == null) {
483 - res = linkAllocs.putIfAbsent(key, new ArrayList<LinkResourceAllocations>()); 492 + res = linkAllocs.putIfAbsent(key, new ArrayList<>());
484 if (res == null) { 493 if (res == null) {
485 return Collections.emptyList(); 494 return Collections.emptyList();
486 } else { 495 } else {
......