tmf: Bug 495219: Fix NPE in checkpoint indexer seeking on disposed trace
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / internal / tmf / core / trace / indexer / FlatArray.java
index 64bfa085bb8a12ae22bce786c2d186b919d76ac0..4df395d7dbf4efbdae37eb6790400201964222cf 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013, 2014 Ericsson
+ * Copyright (c) 2013, 2016 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -90,11 +90,14 @@ public class FlatArray extends AbstractFileCheckpointCollection {
         ITmfCheckpoint checkpoint = null;
         try {
             long pos = getHeader().getSize() + fCheckpointSize * rank;
+            if (getRandomAccessFile() == null) {
+                return null;
+            }
             getRandomAccessFile().seek(pos);
             fByteBuffer.clear();
             getRandomAccessFile().read(fByteBuffer.array());
             ITmfLocation location = getTrace().restoreLocation(fByteBuffer);
-            ITmfTimestamp timeStamp = new TmfTimestamp(fByteBuffer);
+            ITmfTimestamp timeStamp = TmfTimestamp.create(fByteBuffer);
             checkpoint = new TmfCheckpoint(timeStamp, location, fByteBuffer);
         } catch (IOException e) {
             Activator.logError(MessageFormat.format(Messages.FlatArray_IOErrorReading, getFile()), e);
@@ -136,7 +139,6 @@ public class FlatArray extends AbstractFileCheckpointCollection {
                 lower = middle + 1;
             }
         }
-        long insertionPoint = lower;
-        return -(insertionPoint) - 1;
+        return -(lower) - 1;
     }
 }
This page took 0.036934 seconds and 5 git commands to generate.