@@ -370,6 +370,31 @@ void testMetadataParsing() throws TransformerException, NoSuchAlgorithmException
370370 checkTransform (metadata , "90022311886271402508155234494196354960301469636090129252744270615851988530557" );
371371 }
372372
373+ /**
374+ * PDFBOX-6029: serialize an empty date property, this brought a NullPointerException.
375+ *
376+ * @throws XmpParsingException
377+ * @throws TransformerException
378+ * @throws NoSuchAlgorithmException
379+ */
380+ @ Test
381+ void testEmptyDate () throws XmpParsingException , TransformerException , NoSuchAlgorithmException
382+ {
383+ String xmpmeta = "<?xpacket begin=\" \" id=\" W5M0MpCehiHzreSzNTczkc9d\" ?>\n "
384+ + "<x:xmpmeta x:xmptk=\" Adobe XMP Core 4.2.1-c041 52.342996, 2008/05/07-20:48:00\" xmlns:x=\" adobe:ns:meta/\" >\n "
385+ + " <rdf:RDF xmlns:rdf=\" http://www.w3.org/1999/02/22-rdf-syntax-ns#\" >\n "
386+ + " <rdf:Description rdf:about=\" \" xmlns:xmp=\" http://ns.adobe.com/xap/1.0/\" >\n "
387+ + " <xmp:CreateDate></xmp:CreateDate>\n "
388+ + " </rdf:Description>\n "
389+ + " </rdf:RDF>\n "
390+ + "</x:xmpmeta>\n "
391+ + "<?xpacket end=\" w\" ?>" ;
392+ DomXmpParser xmpParser = new DomXmpParser ();
393+ xmpParser .setStrictParsing (false );
394+ XMPMetadata xmp = xmpParser .parse (xmpmeta .getBytes ());
395+ checkTransform (xmp , "12127125812762553969536294425864809210802519304519294152028982122058554009237" );
396+ }
397+
373398 private void checkTransform (XMPMetadata metadata , String expected )
374399 throws TransformerException , NoSuchAlgorithmException
375400 {
@@ -378,6 +403,7 @@ private void checkTransform(XMPMetadata metadata, String expected)
378403 byte [] ba = replaced .getBytes (StandardCharsets .UTF_8 );
379404 byte [] digest = MessageDigest .getInstance ("SHA-256" ).digest (ba );
380405 String result = new BigInteger (1 , digest ).toString ();
406+ System .out .println (replaced );
381407 assertEquals (expected , result );
382408 }
383409}
0 commit comments