Author: desruisseaux
Date: Mon Feb 26 17:56:23 2018
New Revision: 1825390

URL: http://svn.apache.org/viewvc?rev=1825390&view=rev
Log:
Remove a logging message that does not appear to be useful in practice (about 
JAXB attempting to add a null element in a collection).
Avoid direct dependencies of CheckedArrayList to Context, in prevision of 
moving XML-related classes to sis-metadata in a future commit.

Modified:
    
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ServicesForUtility.java
    
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
    
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/constraint/DefaultLegalConstraintsTest.java
    
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CheckedArrayList.java
    
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/MetadataServices.java
    
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java

Modified: 
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ServicesForUtility.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ServicesForUtility.java?rev=1825390&r1=1825389&r2=1825390&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ServicesForUtility.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ServicesForUtility.java
 [UTF-8] Mon Feb 26 17:56:23 2018
@@ -32,6 +32,7 @@ import org.apache.sis.internal.util.Cons
 import org.apache.sis.internal.util.MetadataServices;
 import org.apache.sis.internal.metadata.sql.Initializer;
 import org.apache.sis.internal.system.Loggers;
+import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.metadata.iso.ImmutableIdentifier;
 import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.metadata.iso.citation.DefaultCitation;
@@ -49,7 +50,7 @@ import static java.util.Collections.sing
  * Implements the metadata services needed by the {@code "sis-utility"} module.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.6
  * @module
  */
@@ -61,6 +62,17 @@ public final class ServicesForUtility ex
     }
 
     /**
+     * {@code true} if this thread is in the process of reading a XML document 
with JAXB.
+     *
+     * @return if XML unmarshalling is in progress in current thread.
+     */
+    @Override
+    public boolean isUnmarshalling() {
+        final Context context = Context.current();
+        return (context != null) && !Context.isFlagSet(context, 
Context.MARSHALLING);
+    }
+
+    /**
      * Returns the constant defined in the {@link Citations} class for the 
given name.
      *
      * @param  name  the name of one of the citation constants defined in the 
{@code Citations} class.

Modified: 
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java?rev=1825390&r1=1825389&r2=1825390&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
 [UTF-8] Mon Feb 26 17:56:23 2018
@@ -21,18 +21,13 @@ import java.util.Locale;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.Collection;
-import java.util.logging.LogRecord;
 import java.net.URISyntaxException;
-import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.JAXBException;
 import org.opengis.metadata.MetadataScope;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.citation.DateType;
 import org.opengis.metadata.maintenance.ScopeCode;
-import org.apache.sis.xml.XML;
 import org.apache.sis.xml.Namespaces;
-import org.apache.sis.xml.MarshallerPool;
-import org.apache.sis.util.logging.WarningListener;
 import org.apache.sis.util.iso.SimpleInternationalString;
 import org.apache.sis.metadata.iso.citation.DefaultCitation;
 import org.apache.sis.metadata.iso.citation.DefaultCitationDate;
@@ -59,7 +54,7 @@ import static org.apache.sis.test.TestUt
  * @module
  */
 @DependsOn(org.apache.sis.internal.metadata.OtherLocalesTest.class)
-public final strictfp class DefaultMetadataTest extends XMLTestCase implements 
WarningListener<Object> {
+public final strictfp class DefaultMetadataTest extends XMLTestCase {
     /**
      * A flag for tracing workarounds for allowing some tests to pass despite 
regression.
      * This boolean should be set to {@code false} and removed after the 
following issues has been fixed:
@@ -71,55 +66,6 @@ public final strictfp class DefaultMetad
     public static final boolean REGRESSION = true;
 
     /**
-     * The resource key for the message of the warning that occurred while 
unmarshalling a XML fragment,
-     * or {@code null} if none.
-     */
-    private Object resourceKey;
-
-    /**
-     * The parameter of the warning that occurred while unmarshalling a XML 
fragment, or {@code null} if none.
-     */
-    private Object[] parameters;
-
-    /**
-     * For internal {@code DefaultMetadata} usage.
-     *
-     * @return {@code Object.class}.
-     */
-    @Override
-    public Class<Object> getSourceClass() {
-        return Object.class;
-    }
-
-    /**
-     * Invoked when a warning occurred while unmarshalling a test XML 
fragment. This method ensures that no other
-     * warning occurred before this method call (i.e. each test is allowed to 
cause at most one warning), then
-     * remember the warning parameters for verification by the test method.
-     *
-     * @param source   ignored.
-     * @param warning  the warning.
-     */
-    @Override
-    public void warningOccured(final Object source, final LogRecord warning) {
-        assertNull(resourceKey);
-        assertNull(parameters);
-        assertNotNull(resourceKey = warning.getMessage());
-        assertNotNull(parameters  = warning.getParameters());
-    }
-
-    /**
-     * Unmarshalls the given XML fragment.
-     */
-    private DefaultMetadata unmarshal(final String xml) throws JAXBException {
-        final MarshallerPool pool = getMarshallerPool();
-        final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
-        unmarshaller.setProperty(XML.WARNING_LISTENER, this);
-        final Object c = unmarshal(unmarshaller, xml);
-        pool.recycle(unmarshaller);
-        return (DefaultMetadata) c;
-    }
-
-    /**
      * Tests unmarshalling of a metadata having a collection that contains no 
element.
      * This was used to cause a {@code NullPointerException} prior SIS-139 fix.
      *
@@ -129,7 +75,7 @@ public final strictfp class DefaultMetad
      */
     @Test
     public void testEmptyCollection() throws JAXBException {
-        final DefaultMetadata metadata = unmarshal(
+        final DefaultMetadata metadata = unmarshal(DefaultMetadata.class,
                 "<mdb:MD_Metadata xmlns:mdb=\"" + Namespaces.MDB + "\">\n" +
                 "  <mdb:contact/>\n" +
                 "</mdb:MD_Metadata>");
@@ -137,11 +83,6 @@ public final strictfp class DefaultMetad
          * Verify metadata property.
          */
         assertTrue(metadata.getContacts().isEmpty());
-        /*
-         * Verify warning message emitted during unmarshalling.
-         */
-        assertEquals("warning", "NullCollectionElement_1", resourceKey);
-        assertArrayEquals("warning", new String[] 
{"CheckedArrayList<Responsibility>"}, parameters);
     }
 
     /**

Modified: 
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/constraint/DefaultLegalConstraintsTest.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/constraint/DefaultLegalConstraintsTest.java?rev=1825390&r1=1825389&r2=1825390&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/constraint/DefaultLegalConstraintsTest.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/constraint/DefaultLegalConstraintsTest.java
 [UTF-8] Mon Feb 26 17:56:23 2018
@@ -16,14 +16,9 @@
  */
 package org.apache.sis.metadata.iso.constraint;
 
-import java.util.logging.LogRecord;
-import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.JAXBException;
 import org.opengis.metadata.constraint.Restriction;
-import org.apache.sis.xml.XML;
 import org.apache.sis.xml.Namespaces;
-import org.apache.sis.xml.MarshallerPool;
-import org.apache.sis.util.logging.WarningListener;
 import org.apache.sis.internal.jaxb.LegacyNamespaces;
 import org.apache.sis.test.XMLTestCase;
 import org.junit.Test;
@@ -42,56 +37,7 @@ import static org.apache.sis.test.TestUt
  * @since   0.4
  * @module
  */
-public final strictfp class DefaultLegalConstraintsTest extends XMLTestCase 
implements WarningListener<Object> {
-    /**
-     * The resource key for the message of the warning that occurred while 
unmarshalling a XML fragment,
-     * or {@code null} if none.
-     */
-    private Object resourceKey;
-
-    /**
-     * The parameter of the warning that occurred while unmarshalling a XML 
fragment, or {@code null} if none.
-     */
-    private Object[] parameters;
-
-    /**
-     * For internal {@code DefaultLegalConstraints} usage.
-     *
-     * @return {@code Object.class}.
-     */
-    @Override
-    public Class<Object> getSourceClass() {
-        return Object.class;
-    }
-
-    /**
-     * Invoked when a warning occurred while unmarshalling a test XML 
fragment. This method ensures that no other
-     * warning occurred before this method call (i.e. each test is allowed to 
cause at most one warning), then
-     * remember the warning parameters for verification by the test method.
-     *
-     * @param source   ignored.
-     * @param warning  the warning.
-     */
-    @Override
-    public void warningOccured(final Object source, final LogRecord warning) {
-        assertNull(resourceKey);
-        assertNull(parameters);
-        assertNotNull(resourceKey = warning.getMessage());
-        assertNotNull(parameters  = warning.getParameters());
-    }
-
-    /**
-     * Unmarshals the given XML fragment.
-     */
-    private DefaultLegalConstraints unmarshal(final String xml) throws 
JAXBException {
-        final MarshallerPool pool = getMarshallerPool();
-        final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
-        unmarshaller.setProperty(XML.WARNING_LISTENER, this);
-        final Object c = unmarshal(unmarshaller, xml);
-        pool.recycle(unmarshaller);
-        return (DefaultLegalConstraints) c;
-    }
-
+public final strictfp class DefaultLegalConstraintsTest extends XMLTestCase {
     /**
      * Tests unmarshalling of an element containing an empty {@code 
codeListValue} attribute.
      * This was used to cause a {@code NullPointerException} prior SIS-157 fix.
@@ -102,7 +48,7 @@ public final strictfp class DefaultLegal
      */
     @Test
     public void testUnmarshallEmptyCodeListValue() throws JAXBException {
-        final DefaultLegalConstraints c = unmarshal(
+        final DefaultLegalConstraints c = 
unmarshal(DefaultLegalConstraints.class,
                 "<mco:MD_LegalConstraints xmlns:mco=\"" + Namespaces.MCO + 
"\">\n" +
                 "  <mco:accessConstraints>\n" +
                 "    <mco:MD_RestrictionCode 
codeListValue=\"intellectualPropertyRights\" 
codeList=\"http://standards.iso.org/iso/19115/resources/Codelist/cat/codelists.xml#MD_RestrictionCode\"/>\n"
 +
@@ -116,11 +62,6 @@ public final strictfp class DefaultLegal
          */
         assertEquals("accessConstraints", 
Restriction.INTELLECTUAL_PROPERTY_RIGHTS, 
getSingleton(c.getAccessConstraints()));
         assertTrue("useConstraints", c.getUseConstraints().isEmpty());
-        /*
-         * Verify warning message emitted during unmarshalling.
-         */
-        assertEquals("warning", "NullCollectionElement_1", resourceKey);
-        assertArrayEquals("warning", new String[] 
{"CodeListSet<Restriction>"}, parameters);
     }
 
     /**
@@ -145,7 +86,7 @@ public final strictfp class DefaultLegal
         final DefaultLegalConstraints c = new DefaultLegalConstraints();
         c.setUseConstraints(singleton(Restriction.LICENCE));
         assertXmlEquals(xml, marshal(c), "xmlns:*");
-        DefaultLegalConstraints actual = unmarshal(xml);
+        DefaultLegalConstraints actual = 
unmarshal(DefaultLegalConstraints.class, xml);
         assertSame(Restriction.LICENCE, 
getSingleton(actual.getUseConstraints()));
         assertEquals(c, actual);
         /*
@@ -163,7 +104,7 @@ public final strictfp class DefaultLegal
                 "</gmd:MD_LegalConstraints>\n";
 
         assertXmlEquals(xml, marshal(c, VERSION_2007), "xmlns:*");
-        actual = unmarshal(xml);
+        actual = unmarshal(DefaultLegalConstraints.class, xml);
         assertSame(Restriction.LICENCE, 
getSingleton(actual.getUseConstraints()));
         assertEquals(c, actual);
     }

Modified: 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CheckedArrayList.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CheckedArrayList.java?rev=1825390&r1=1825389&r2=1825390&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CheckedArrayList.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CheckedArrayList.java
 [UTF-8] Mon Feb 26 17:56:23 2018
@@ -21,7 +21,6 @@ import java.util.AbstractList;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.util.Classes;
 import org.apache.sis.util.ArraysExt;
 import org.apache.sis.util.NullArgumentException;
@@ -47,7 +46,7 @@ import static org.apache.sis.util.Argume
  * holes are known to exist in use cases like {@code sublist(…).set(…)} or 
when using the list iterator.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.5
+ * @version 1.0
  *
  * @param <E>  the type of elements in the list.
  *
@@ -149,6 +148,14 @@ public final class CheckedArrayList<E> e
      * @see <a href="https://issues.apache.org/jira/browse/SIS-157";>SIS-157</a>
      */
     public static String illegalElement(final Collection<?> collection, final 
Object element, final Class<?> expectedType) {
+        /*
+         * Ignore if the current thread is in process of unmarshalling a XML 
document.
+         * This happen when an XML element is empty (e.g. "<cit:contact/>"), 
in which
+         * case JAXB tries to add a null element.
+         */
+        if (MetadataServices.getInstance().isUnmarshalling()) {
+            return null;
+        }
         final short key;
         final Object[] arguments;
         if (element == null) {
@@ -160,13 +167,7 @@ public final class CheckedArrayList<E> e
             key = Errors.Keys.IllegalArgumentClass_3;
             arguments = new Object[] {"element", expectedType, 
element.getClass()};
         }
-        final Context context = Context.current();
-        if (context != null) {
-            Context.warningOccured(context, collection.getClass(), "add", 
Errors.class, key, arguments);
-            return null;
-        } else {
-            return Errors.format(key, arguments);
-        }
+        return Errors.format(key, arguments);
     }
 
     /**

Modified: 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/MetadataServices.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/MetadataServices.java?rev=1825390&r1=1825389&r2=1825390&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/MetadataServices.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/MetadataServices.java
 [UTF-8] Mon Feb 26 17:56:23 2018
@@ -31,7 +31,7 @@ import org.apache.sis.internal.system.Op
  * implementation using Java reflection.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.6
  * @module
  */
@@ -92,6 +92,15 @@ public class MetadataServices extends Op
     }
 
     /**
+     * {@code true} if this thread is in the process of reading a XML document 
with JAXB.
+     *
+     * @return if XML unmarshalling is in progress in current thread.
+     */
+    public boolean isUnmarshalling() {
+        return false;
+    }
+
+    /**
      * Returns the constant defined in the {@link 
org.apache.sis.metadata.iso.citation.Citations} class for the
      * given name. This is used at {@link 
org.apache.sis.internal.simple.CitationConstant} deserialization time,
      * for which the two citations of interest are {@code "ISBN"} 
(International Standard Book Number) and

Modified: 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java?rev=1825390&r1=1825389&r2=1825390&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java
 [UTF-8] Mon Feb 26 17:56:23 2018
@@ -30,7 +30,7 @@
  * so some serialized classes still exist in this package.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.3
+ * @version 1.0
  * @since   0.3
  * @module
  */


Reply via email to