Adjust test with deeply nested file for JDK 25

It seems JDK 25 introduces more checks when parsing XML
Also apply some IDE suggestions and fix deprecation warnings
This commit is contained in:
Dominik Stadler 2025-08-10 16:07:55 +02:00
parent 009b6501f2
commit 92565ea07c

View File

@ -29,6 +29,7 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.poi.POIDataSamples;
import org.apache.poi.POIException;
import org.apache.poi.ooxml.POIXMLException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagePartName;
@ -137,11 +138,11 @@ class TestXWPFBugs {
void bug59058() throws IOException, XmlException {
String[] files = {"bug57031.docx", "bug59058.docx"};
for (String f : files) {
ZipFile zf = new ZipFile(samples.getFile(f));
ZipArchiveEntry entry = zf.getEntry("word/document.xml");
DocumentDocument document = DocumentDocument.Factory.parse(zf.getInputStream(entry));
assertNotNull(document);
zf.close();
try (ZipFile zf = ZipFile.builder().setFile(samples.getFile(f)).get()) {
ZipArchiveEntry entry = zf.getEntry("word/document.xml");
DocumentDocument document = DocumentDocument.Factory.parse(zf.getInputStream(entry));
assertNotNull(document);
}
}
}
@ -149,11 +150,11 @@ class TestXWPFBugs {
void missingXsbs() throws IOException, XmlException {
String[] files = {"bib-chernigovka.netdo.ru_download_docs_17459.docx"};
for (String f : files) {
ZipFile zf = new ZipFile(samples.getFile(f));
ZipArchiveEntry entry = zf.getEntry("word/document.xml");
DocumentDocument document = DocumentDocument.Factory.parse(zf.getInputStream(entry));
assertNotNull(document);
zf.close();
try (ZipFile zf = ZipFile.builder().setFile(samples.getFile(f)).get()) {
ZipArchiveEntry entry = zf.getEntry("word/document.xml");
DocumentDocument document = DocumentDocument.Factory.parse(zf.getInputStream(entry));
assertNotNull(document);
}
}
}
@ -277,11 +278,19 @@ class TestXWPFBugs {
}
@Test
public void testDeepTableCell() throws Exception {
// Document contains a table with nested cells.
IOException ex = assertThrows(IOException.class,
() -> XWPFTestDataSamples.openSampleDocument("deep-table-cell.docx"));
assertInstanceOf(POIException.class, ex.getCause());
assertTrue(ex.getMessage().contains("Node depth exceeds maximum supported depth"));
public void testDeepTableCell() {
try {
// Document contains a table with nested cells.
//noinspection resource
XWPFTestDataSamples.openSampleDocument("deep-table-cell.docx");
fail("Should catch exception");
} catch (POIXMLException e) {
// JDK 25+ does more checks, so more than one exception are possible
assertTrue(e.getMessage().contains("The element \"w:t\" has a depth"),
"Had: " + e);
} catch (IOException e) {
assertInstanceOf(POIException.class, e.getCause());
assertTrue(e.getMessage().contains("Node depth exceeds maximum supported depth"));
}
}
}