From b8720a16a04dd26ea18bf991b91efb0fe8eee35e Mon Sep 17 00:00:00 2001 From: jstaerk Date: Mon, 3 Jun 2024 08:04:15 +0200 Subject: [PATCH] small possible nullpointerex fix (for accidental non-pdf/a-PDFs), new test --- History.md | 3 + .../ZUGFeRD/ZUGFeRDImporter.java | 3 + .../validator/XMLValidatorTest.java | 26 +++ .../test/resources/EN16931_Einfach.ubl.xml | 159 ++++++++++++++++++ 4 files changed, 191 insertions(+) create mode 100644 validator/src/test/resources/EN16931_Einfach.ubl.xml diff --git a/History.md b/History.md index ec93baaa..8c5d03fc 100644 --- a/History.md +++ b/History.md @@ -1,4 +1,7 @@ +- support pdf export/visualization to PDF, thanks to Heavenfighter #387 allow embedd fonts from jar-file for pdf creation #388 +- Fix #389: ClassCastException: ZUGFeRDExporterFromA3 + 2.11.0 ======= 2024-05-22 diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java index d72b9b6b..6cc33371 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java @@ -142,6 +142,9 @@ public class ZUGFeRDImporter { } else { final List> kids = etn.getKids(); + if (kids == null) { + return; + } for (final PDNameTreeNode node : kids) { final Map namesL = node.getNames(); extractFiles(namesL); diff --git a/validator/src/test/java/org/mustangproject/validator/XMLValidatorTest.java b/validator/src/test/java/org/mustangproject/validator/XMLValidatorTest.java index 685b0eec..3751633c 100644 --- a/validator/src/test/java/org/mustangproject/validator/XMLValidatorTest.java +++ b/validator/src/test/java/org/mustangproject/validator/XMLValidatorTest.java @@ -258,4 +258,30 @@ public class XMLValidatorTest extends ResourceCase { assertTrue(noExceptions); } + + + public void testUBLValidation() { + ValidationContext ctx = new ValidationContext(null); + XMLValidator xv = new XMLValidator(ctx); + XPathEngine xpath = new JAXPXPathEngine(); + + boolean noExceptions = true; + File tempFile = getResourceAsFile("EN16931_Einfach.ubl.xml"); + try { + xv.setFilename(tempFile.getAbsolutePath()); + xv.validate(); + + Source source = Input.fromString("" + xv.getXMLResult() + "").build(); + String content = xpath.evaluate("/validation/summary/@status", source); + assertEquals("valid", content); + + + } catch (IrrecoverableValidationError e) { + + noExceptions = false; + } + assertTrue(noExceptions); + + } + } diff --git a/validator/src/test/resources/EN16931_Einfach.ubl.xml b/validator/src/test/resources/EN16931_Einfach.ubl.xml new file mode 100644 index 00000000..d0685ac1 --- /dev/null +++ b/validator/src/test/resources/EN16931_Einfach.ubl.xml @@ -0,0 +1,159 @@ + + + urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0 + urn:fdc:peppol.eu:2017:poacc:billing:01:1.0 + 471102 + 2018-03-05 + 380 + Rechnung gemäß Bestellung vom 01.03.2018. + #REG#Lieferant GmbH +Lieferantenstraße 20 +80333 München +Deutschland +Geschäftsführer: Hans Muster +Handelsregisternummer: H A 123 + + EUR + + + + 4000001123452 + + + Lieferant GmbH + + + Lieferantenstraße 20 + München + 80333 + + DE + + + + 201/113/40209 + + FC + + + + DE123456789 + + VAT + + + + Lieferant GmbH + + + + + + + GE2020211 + + + Kunden AG Mitte + + + Kundenstraße 15 + Frankfurt + 69876 + + DE + + + + Kunden AG Mitte + + + + + 2018-03-05 + + + Zahlbar innerhalb 30 Tagen netto bis 04.04.2018, 3% Skonto innerhalb 10 Tagen bis 15.03.2018 + + + 56.87 + + 275 + 19.25 + + S + 7 + + VAT + + + + + 198 + 37.62 + + S + 19 + + VAT + + + + + + 473 + 473 + 529.87 + 0 + 0 + 0 + 529.87 + + + 1 + 20 + 198 + + Trennblätter A4 + + TB100A4 + + + 4012345001235 + + + S + 19 + + VAT + + + + + 9.9 + + + + 2 + 50 + 275 + + Joghurt Banane + + ARNR2 + + + 4000050986428 + + + S + 7 + + VAT + + + + + 5.5 + + +