From 0ea72ce3edeb7a643befd885c2852678c3fd37b5 Mon Sep 17 00:00:00 2001 From: Nate Jensen Date: Thu, 19 Jun 2014 09:51:10 -0500 Subject: [PATCH 1/2] Issue #3248 ensure that a locking file output streams obtains the lock before calling the FileOutputStream constructor Change-Id: I210ac789322c975cb93584facb3eec417f5097f2 Former-commit-id: 4558fe5862e93766fdad8c0db5881492e59afc7f [formerly 845483346f9f0b1dd4e4ebee4fe88808322491cc] [formerly 65eb76ff66d40ad9f1817d13a277ac153aee10f3 [formerly 599f2598f711ce2ae6ac69ed78a90502a84d2716]] Former-commit-id: 65eb76ff66d40ad9f1817d13a277ac153aee10f3 Former-commit-id: d1766dc991599c29e3b9fc28f1c440701228ad44 --- .../localization/LockingFileOutputStream.java | 50 ++++++++++++++++--- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/LockingFileOutputStream.java b/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/LockingFileOutputStream.java index 9c9cf6b5f4..38e6595efa 100644 --- a/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/LockingFileOutputStream.java +++ b/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/LockingFileOutputStream.java @@ -35,7 +35,9 @@ import com.raytheon.uf.common.localization.FileLocker.Type; * * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Jun 23, 2011 mschenke Initial creation + * Jun 23, 2011 mschenke Initial creation + * Jun 05, 2014 3248 njensen Fix constructors so lock is obtained + * before super constructor called * * * @@ -46,7 +48,9 @@ import com.raytheon.uf.common.localization.FileLocker.Type; public class LockingFileOutputStream extends FileOutputStream { private File file; - + + private final Object locker; + /** * Create a new LockingFileOuputStream, creates an exclusive lock on the * file @@ -55,9 +59,7 @@ public class LockingFileOutputStream extends FileOutputStream { * @throws FileNotFoundException */ public LockingFileOutputStream(File file) throws FileNotFoundException { - super(file); - this.file = file; - FileLocker.lock(this, file, Type.WRITE); + this(file, false); } /** @@ -70,9 +72,40 @@ public class LockingFileOutputStream extends FileOutputStream { */ public LockingFileOutputStream(File file, boolean isAppending) throws FileNotFoundException { + this(file, isAppending, new Object()); + } + + /** + * Intentionally private constructor that takes a locker object to provide a + * unique lock tied to this stream instance. This constructor enforces that + * the FileLocker lock will be obtained before the super constructor is + * called. Otherwise, if isAppending is false, the super constructor will + * set the file length to zero, wiping out the contents, and we absolutely + * must have the write lock before that. + * + * @param file + * @param isAppending + * @param locker + * @throws FileNotFoundException + */ + private LockingFileOutputStream(File file, boolean isAppending, Object locker) throws FileNotFoundException { + this(file, isAppending, locker, FileLocker.lock(locker, file, Type.WRITE)); + } + + /** + * Intentionally private constructor that should be called after the file + * lock is obtained. + * + * @param file + * @param isAppending + * @param locker + * @param gotLock + * @throws FileNotFoundException + */ + private LockingFileOutputStream(File file, boolean isAppending, Object locker, boolean gotLock) throws FileNotFoundException { super(file, isAppending); this.file = file; - FileLocker.lock(this, file, Type.WRITE); + this.locker = locker; } @Override @@ -106,7 +139,10 @@ public class LockingFileOutputStream extends FileOutputStream { } } + /** + * Unlocks the file lock associated with the stream. + */ public void unlock() { - FileLocker.unlock(this, file); + FileLocker.unlock(locker, file); } } From 9edc1153de1ce23c06a510eda3ad26c0371de78a Mon Sep 17 00:00:00 2001 From: Ben Steffensmeier Date: Tue, 24 Jun 2014 10:57:02 -0500 Subject: [PATCH 2/2] Issue #2661 Fix grid time series errors when there is no data. Former-commit-id: 2c1988017e049932f2ec84b577f73871defb09e5 [formerly aaa146b2d0c73c2f512872770c16bc88e16f50f7] [formerly 46b86885974c538653c21034340f963b23a23818 [formerly 2fdb5867131b54f5d74ef3edd8c621c8807d4d99]] Former-commit-id: 46b86885974c538653c21034340f963b23a23818 Former-commit-id: c184936340241de7614231047a4b15ee693509fc --- .../d2d/xy/adapters/timeseries/GridTimeSeriesAdapter.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cave/com.raytheon.uf.viz.d2d.xy.adapters/src/com/raytheon/uf/viz/d2d/xy/adapters/timeseries/GridTimeSeriesAdapter.java b/cave/com.raytheon.uf.viz.d2d.xy.adapters/src/com/raytheon/uf/viz/d2d/xy/adapters/timeseries/GridTimeSeriesAdapter.java index 3293753111..6126d3df1c 100644 --- a/cave/com.raytheon.uf.viz.d2d.xy.adapters/src/com/raytheon/uf/viz/d2d/xy/adapters/timeseries/GridTimeSeriesAdapter.java +++ b/cave/com.raytheon.uf.viz.d2d.xy.adapters/src/com/raytheon/uf/viz/d2d/xy/adapters/timeseries/GridTimeSeriesAdapter.java @@ -322,8 +322,9 @@ public class GridTimeSeriesAdapter extends dataPoint = new XYData(time, value); } } - - data.add(dataPoint); + if (dataPoint != null){ + data.add(dataPoint); + } } XYDataList list = new XYDataList();