This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit fe2cbc1694d4c531c87b6cd11b135d598e122a82 Author: Martin Desruisseaux <[email protected]> AuthorDate: Sun Sep 8 17:07:41 2019 +0200 Throws an exception on attempt to use a closed StorageConnector. This is necessary for avoiding NullPointerException later. --- .../main/java/org/apache/sis/internal/storage/Resources.java | 5 +++++ .../java/org/apache/sis/internal/storage/Resources.properties | 1 + .../org/apache/sis/internal/storage/Resources_fr.properties | 1 + .../main/java/org/apache/sis/storage/StorageConnector.java | 11 +++++++++-- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources.java index 03bc371..c062fab 100644 --- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources.java +++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources.java @@ -122,6 +122,11 @@ public final class Resources extends IndexedResourceBundle { public static final short ClosedReader_1 = 4; /** + * This storage connector is closed. + */ + public static final short ClosedStorageConnector = 56; + + /** * This {0} writer is closed. */ public static final short ClosedWriter_1 = 5; diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources.properties b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources.properties index a6d6ecc..39a707a 100644 --- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources.properties +++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources.properties @@ -30,6 +30,7 @@ CanNotReadFile_3 = Can not read line {2} of \u201c{1}\u201d as CanNotReadFile_4 = Can not read after column {3} of line {2} of \u201c{1}\u201d as part of a file in the {0} format. CanNotRemoveResource_2 = Can not remove resource \u201c{1}\u201d from aggregate \u201c{0}\u201d. CanNotStoreResourceType_2 = Can not save resources of type \u2018{1}\u2019 in a \u201c{0}\u201d store. +ClosedStorageConnector = This storage connector is closed. ClosedReader_1 = This {0} reader is closed. ClosedWriter_1 = This {0} writer is closed. ConcurrentRead_1 = One or more read operations are in progress in the \u201c{0}\u201d data store. diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources_fr.properties b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources_fr.properties index 6fbc132..0294938 100644 --- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources_fr.properties +++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources_fr.properties @@ -35,6 +35,7 @@ CanNotReadFile_3 = Ne peut pas lire la ligne {2} de \u00ab\u202 CanNotReadFile_4 = Ne peut pas lire apr\u00e8s la colonne {3} de la ligne {2} de \u00ab\u202f{1}\u202f\u00bb comme une partie d\u2019un fichier au format {0}. CanNotRemoveResource_2 = Ne peut pas supprimer la ressource \u00ab\u202f{1}\u202f\u00bb de l\u2019agr\u00e9gat \u00ab\u202f{0}\u202f\u00bb. CanNotStoreResourceType_2 = Ne peut pas enregistrer des ressources de type \u2018{1}\u2019 dans un entrep\u00f4t de donn\u00e9es \u00ab\u202f{0}\u202f\u00bb. +ClosedStorageConnector = Ce connecteur est ferm\u00e9. ClosedReader_1 = Ce lecteur {0} est ferm\u00e9. ClosedWriter_1 = Cet encodeur {0} est ferm\u00e9. ConcurrentRead_1 = Une ou plusieurs op\u00e9rations de lecture sont en cours sur les donn\u00e9es de \u00ab\u202f{0}\u202f\u00bb. diff --git a/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java b/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java index 363177d..8f0521c 100644 --- a/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java +++ b/storage/sis-storage/src/main/java/org/apache/sis/storage/StorageConnector.java @@ -86,7 +86,7 @@ import org.apache.sis.setup.OptionKey; * is serializable.</p> * * @author Martin Desruisseaux (Geomatys) - * @version 0.8 + * @version 1.0 * @since 0.3 * @module */ @@ -225,8 +225,9 @@ public class StorageConnector implements Serializable { private Map<OptionKey<?>, Object> options; /** - * Views of {@link #storage} as instances of different types than the type of the object given to the constructor. + * Views of {@link #storage} as instances of types different than the type of the object given to the constructor. * The {@code null} reference can appear in various places: + * * <ul> * <li>A non-existent entry (equivalent to an entry associated to the {@code null} value) means that the value * has not yet been computed.</li> @@ -236,6 +237,8 @@ public class StorageConnector implements Serializable { * <li>By convention, the {@code null} key is associated to the {@link #storage} value.</li> * </ul> * + * An empty map means that this {@code StorageConnector} has been closed. + * * @see #addView(Class, Object, Class, byte) * @see #getView(Class) * @see #getStorageAs(Class) @@ -757,6 +760,7 @@ public class StorageConnector implements Serializable { * types listed in javadoc but no view can be created for the source given at construction time. * @throws IllegalArgumentException if the given {@code type} argument is not one of the supported types * listed in this javadoc or in subclass javadoc. + * @throws IllegalStateException if this {@code StorageConnector} has been {@linkplain #closeAllExcept closed}. * @throws DataStoreException if an error occurred while opening a stream or database connection. * * @see #getStorage() @@ -764,6 +768,9 @@ public class StorageConnector implements Serializable { */ public <T> T getStorageAs(final Class<T> type) throws IllegalArgumentException, DataStoreException { ArgumentChecks.ensureNonNull("type", type); + if (views != null && views.isEmpty()) { + throw new IllegalStateException(Resources.format(Resources.Keys.ClosedStorageConnector)); + } /* * Verify if the cache contains an instance created by a previous invocation of this method. * Note that InputStream may need to be reseted if it has been used indirectly by other kind
