sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1683707 - /sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ServicesForUtility.java
Date Fri, 05 Jun 2015 10:44:47 GMT
Author: desruisseaux
Date: Fri Jun  5 10:44:47 2015
New Revision: 1683707

URL: http://svn.apache.org/r1683707
Log:
Fixed a NullPointerException when a citation constant is built during XML serialization.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ServicesForUtility.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=1683707&r1=1683706&r2=1683707&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] Fri Jun  5 10:44:47 2015
@@ -16,9 +16,11 @@
  */
 package org.apache.sis.internal.metadata;
 
+import java.util.Collection;
 import org.opengis.metadata.citation.Role;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.citation.PresentationForm;
+import org.opengis.metadata.citation.Responsibility;
 import org.apache.sis.internal.simple.SimpleCitation;
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.internal.util.MetadataServices;
@@ -29,6 +31,8 @@ import org.apache.sis.metadata.iso.citat
 import org.apache.sis.metadata.iso.citation.DefaultResponsibility;
 import org.apache.sis.util.iso.Types;
 
+import static java.util.Collections.singleton;
+
 
 /**
  * Implements the metadata services needed by the {@code "sis-utility"} module.
@@ -150,16 +154,27 @@ public final class ServicesForUtility ex
             }
             default: return super.createCitation(key);
         }
+        /*
+         * Do not use the 'c.getFoo().add(foo)' pattern below. Use the 'c.setFoo(singleton(foo))'
pattern instead.
+         * This is because this method may be invoked during XML serialization, in which
case some getter methods
+         * may return null (for preventing JAXB to marshal some empty elements).
+         */
         final DefaultCitation c = new DefaultCitation(title);
-        if (alternateTitle        != null) c.getAlternateTitles().add(Types.toInternationalString(alternateTitle));
+        if (alternateTitle        != null) c.setAlternateTitles(singleton(Types.toInternationalString(alternateTitle)));
         if (edition               != null) c.setEdition(Types.toInternationalString(edition));
-        if (code                  != null) c.getIdentifiers().add(new ImmutableIdentifier(null,
codeSpace, code, version, null));
+        if (code                  != null) c.setIdentifiers(singleton(new ImmutableIdentifier(null,
codeSpace, code, version, null)));
         if (copyFrom              != null) c.setCitedResponsibleParties(copyFrom.getCitedResponsibleParties());
-        if (presentationForm      != null) c.getPresentationForms().add(presentationForm);
+        if (presentationForm      != null) c.setPresentationForms(singleton(presentationForm));
         if (citedResponsibleParty != null) {
             final DefaultOrganisation organisation = new DefaultOrganisation();
             organisation.setName(Types.toInternationalString(citedResponsibleParty));
-            c.getCitedResponsibleParties().add(new DefaultResponsibility(Role.PRINCIPAL_INVESTIGATOR,
null, organisation));
+            final DefaultResponsibility r = new DefaultResponsibility(Role.PRINCIPAL_INVESTIGATOR,
null, organisation);
+            final Collection<Responsibility> parties = c.getCitedResponsibleParties();
+            if (parties != null) {
+                parties.add(r);
+            } else {
+                c.setCitedResponsibleParties(singleton(r));
+            }
         }
         c.freeze();
         return c;



Mime
View raw message