|
From: __Johan__ <joh...@or...> - 2009-09-02 12:03:37
|
Hi all,
i'm currently working on a project in which the geotools library is used. It
all worked fine, until i tried to supply it with an invalid shapefile.
I use the following code:
DataStore dataStore = null;
try {
// set the connection parameters
final Map<String, Serializable> connectParameters = new HashMap<String,
Serializable>();
connectParameters.put(ShapefileDataStoreFactory.URLP.key, shapeSource);
connectParameters.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key,
true);
// get the datastore
final ShapefileDataStoreFactory f = new ShapefileDataStoreFactory();
dataStore = f.createDataStore(connectParameters);
// we are now connected
String[] typeNames = dataStore.getTypeNames();
String typeName = typeNames[0];
final FeatureSource<SimpleFeatureType, SimpleFeature> featureSource =
dataStore.getFeatureSource(typeName);
featureCollection = featureSource.getFeatures();
if (featureCollection != null) {
LOGGER.info(featureCollection.size() + " features found in shapefile");
} else {
LOGGER.warn("No features found in shapefile");
}
} catch (IOException e) {
LOGGER.error(e.getMessage());
if (dataStore != null) {
dataStore.dispose();
}
throw new Exception("Failure while reading shape file:" + e, e);
}
With the invalid shapefile (just a regular textfile, renamed to .shp), i get
an exception (as expected), but the file remains locked. I know that testing
with a renamed textfile is stupid, but i'd expect that it should work if
someone supplied an invalid file. The files shouldn't remain in lock anyway.
:) I get the following stacktrace:
2-sep-2009 13:02:57
org.geotools.data.shapefile.indexed.IndexedShapefileDataStore <init>
SEVERE: null
2-sep-2009 13:02:57
org.geotools.data.shapefile.indexed.IndexedShapefileDataStore <init>
SEVERE: Wrong magic number, expected 9994, got 825242160
ERROR [xx.xx.geo.ShapeToJtsMapper] Wrong magic number, expected 9994, got
825242160
2-sep-2009 13:02:57 org.geotools.data.shapefile.ShpFiles logCurrentLockers
SEVERE: The following locker still has a lock� read on
file:/c:/temp/test/shp/invalid_test_file.shp by
org.geotools.data.shapefile.shp.ShapefileReader
it was created with the following stack trace
org.geotools.data.shapefile.ShpFilesLocker$Trace: Locking
file:/c:/temp/test/shp/invalid_test_file.shp for read by
org.geotools.data.shapefile.shp.ShapefileReader in thread main
at
org.geotools.data.shapefile.ShpFilesLocker.setTraceException(ShpFilesLocker.java:54)
at
org.geotools.data.shapefile.ShpFilesLocker.<init>(ShpFilesLocker.java:33)
at org.geotools.data.shapefile.ShpFiles.acquireRead(ShpFiles.java:365)
at org.geotools.data.shapefile.ShpFiles.getReadChannel(ShpFiles.java:813)
at
org.geotools.data.shapefile.shp.ShapefileReader.<init>(ShapefileReader.java:142)
at
org.geotools.data.shapefile.indexed.ShapeFileIndexer.index(ShapeFileIndexer.java:168)
at
org.geotools.data.shapefile.indexed.IndexedShapefileDataStore.buildQuadTree(IndexedShapefileDataStore.java:990)
at
org.geotools.data.shapefile.indexed.IndexedShapefileDataStore.createSpatialIndex(IndexedShapefileDataStore.java:230)
at
org.geotools.data.shapefile.indexed.IndexedShapefileDataStore.<init>(IndexedShapefileDataStore.java:208)
at
org.geotools.data.shapefile.ShapefileDataStoreFactory.createDataStore(ShapefileDataStoreFactory.java:213)
at xx.xx.adapt(ShapeToJtsMapper.java:49)
at xx.xx.processContent(Handler.java:74)
at xx.xx.handleEvent(StartHandler.java:40)
at
xx.xx.TestHandler.testBug301FileStillLockedByGeoTools(TestTdkHandler.java:246)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
at
org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at
org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
at
org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at
org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at
org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at
org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Does anyone know how to fix this locking problem? We were using the 2.5.5
version of the geotools library, and i've tried using 2.6-M1 version. This
didn't fix the problem.
--
View this message in context: http://n2.nabble.com/Problems-with-invalid-shapefile-file-remains-locked-tp3566278p3566278.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.
|