]> source.dussan.org Git - poi.git/commitdiff
[bug-66080] XWPFNumbering.addAbstractNum uses abstract numberings count as id
authorPJ Fanning <fanningpj@apache.org>
Sun, 22 May 2022 08:43:06 +0000 (08:43 +0000)
committerPJ Fanning <fanningpj@apache.org>
Sun, 22 May 2022 08:43:06 +0000 (08:43 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1901113 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java

index 9b312603bde5840098e84d858d1bffa0941ba52a..edfb986e99fbc8130a31f086ec9ea346c1cc603a 100644 (file)
@@ -268,6 +268,26 @@ class TestXWPFBugs {
         }
     }
 
+    @Test
+    void test66080() throws IOException {
+        try (XWPFDocument doc = new XWPFDocument()) {
+            XWPFNumbering numbering = doc.createNumbering();
+
+            // Add abstract numbering with id 1
+            addNumberingWithAbstractId(numbering, 1);
+
+            // Add abstract numbering with auto-generated id
+            numbering.addAbstractNum(new XWPFAbstractNum());
+
+            // Check that all abstract numbering ids are unique
+            long uniqueIdCount = numbering
+                    .getAbstractNums().stream()
+                    .map(e -> e.getCTAbstractNum().getAbstractNumId().intValue())
+                    .distinct().count();
+            assertEquals(numbering.getAbstractNums().size(), uniqueIdCount);
+        }
+    }
+
     private static void addNumberingWithAbstractId(XWPFNumbering documentNumbering, int id){
         // create a numbering scheme
         CTAbstractNum cTAbstractNum = CTAbstractNum.Factory.newInstance();