logo separator

[mkgmap-dev] NPE in splitter crosby_integration branch

From Jeffrey Ollie jeff at ocjtech.us on Thu Feb 17 20:25:13 GMT 2011

I think that I've tracked down an NPE in the crosby_integration branch
of the splitter.  The SplitProcessor is using a BlockingQueue to queue
up elements for writing.  The poll() method can potentially return a
null if the queue is empty.  My question is, should the poll() method
call be switched to a take() method call - the take() method will
block if the queue is empty, or should I guard the usage of elements
for null like in the patch below?

Index: src/uk/me/parabola/splitter/SplitProcessor.java
===================================================================
--- src/uk/me/parabola/splitter/SplitProcessor.java	(revision 161)
+++ src/uk/me/parabola/splitter/SplitProcessor.java	(working copy)
@@ -320,13 +320,14 @@
 				} else {
 					synchronized (workPackage) {
 					while (!workPackage.inputQueue.isEmpty()) {
-						ArrayList<Element> elements =null;
+						ArrayList<Element> elements = null;
 						try {
 							elements = workPackage.inputQueue.poll();
-							for (Element element : elements ) {
-								processElement(element, workPackage.writer);
+							if (elements != null) {
+								for (Element element : elements ) {
+									processElement(element, workPackage.writer);
+								}
 							}
-							
 						} catch (IOException e) {
 							throw new RuntimeException("Thread " +
Thread.currentThread().getName() + " failed to write element ", e);
 						}

-- 
Jeff Ollie



More information about the mkgmap-dev mailing list