You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "amos-wnjsoft (via GitHub)" <gi...@apache.org> on 2026/03/20 03:32:51 UTC

[PR] Fix ArrayIndexOutOfBoundsException in XSSFTextParagraph when auto number scheme index is out of range [poi]

amos-wnjsoft opened a new pull request, #1033:
URL: https://github.com/apache/poi/pull/1033

   fix issue #1032 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [PR] Fix ArrayIndexOutOfBoundsException in XSSFTextParagraph when auto number scheme index is out of range [poi]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #1033:
URL: https://github.com/apache/poi/pull/1033#discussion_r2964463235


##########
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTextParagraph.java:
##########
@@ -224,4 +230,37 @@ void testXSSFTextParagraph2() throws IOException {
             assertArrayEquals(run.getFontColorAsBytes(), run2.getFontColorAsBytes());
         }
     }
+
+    @Test
+    public void testBulletAutoNumberSchemeOutOfBounds() {
+        try (XSSFWorkbook wb = new XSSFWorkbook()) {
+            XSSFSheet sheet = wb.createSheet();
+            XSSFDrawing drawing = sheet.createDrawingPatriarch();
+            XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 0, 0, 1, 1));
+
+            // Ensure the paragraph is created correctly
+            XSSFTextParagraph para = shape.addNewTextParagraph();
+
+            // 1. Obtain or create the underlying XML structure
+            CTTextParagraph ctPara = para.getXmlObject();
+            CTTextParagraphProperties pr = ctPara.isSetPPr() ? ctPara.getPPr() : ctPara.addNewPPr();
+
+            // 2. Force a level to avoid ParagraphPropertyFetcher errors
+            pr.setLvl(0);
+
+            // 3. Set an out-of-range autonumber type (e.g. 24)
+            CTTextAutonumberBullet bullet = pr.isSetBuAutoNum() ? pr.getBuAutoNum() : pr.addNewBuAutoNum();
+            bullet.setType(STTextAutonumberScheme.Enum.forInt(24));
+
+            // 4. Execute the test
+            // If you haven't applied the fix, this line will throw AIOOBE
+            // If the fix is applied, this should return ARABIC_PLAIN
+            ListAutoNumber result = para.getBulletAutoNumberScheme();
+
+            assertNotNull(result, "Result should not be null");
+            assertEquals(ListAutoNumber.ARABIC_PLAIN, result, "Should fallback to ARABIC_PLAIN for unknown index");
+        } catch (Exception e) {

Review Comment:
   please remove the catch - it is much better to have the full exception stack trace if an exception is thrown 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [PR] Fix ArrayIndexOutOfBoundsException in XSSFTextParagraph when auto number scheme index is out of range [poi]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning merged PR #1033:
URL: https://github.com/apache/poi/pull/1033


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [PR] Fix ArrayIndexOutOfBoundsException in XSSFTextParagraph when auto number scheme index is out of range [poi]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #1033:
URL: https://github.com/apache/poi/pull/1033#issuecomment-4097005673

   thanks - merged


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [PR] Fix ArrayIndexOutOfBoundsException in XSSFTextParagraph when auto number scheme index is out of range [poi]

Posted by "amos-wnjsoft (via GitHub)" <gi...@apache.org>.
amos-wnjsoft commented on code in PR #1033:
URL: https://github.com/apache/poi/pull/1033#discussion_r2964707536


##########
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTextParagraph.java:
##########
@@ -224,4 +230,37 @@ void testXSSFTextParagraph2() throws IOException {
             assertArrayEquals(run.getFontColorAsBytes(), run2.getFontColorAsBytes());
         }
     }
+
+    @Test
+    public void testBulletAutoNumberSchemeOutOfBounds() {
+        try (XSSFWorkbook wb = new XSSFWorkbook()) {
+            XSSFSheet sheet = wb.createSheet();
+            XSSFDrawing drawing = sheet.createDrawingPatriarch();
+            XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 0, 0, 1, 1));
+
+            // Ensure the paragraph is created correctly
+            XSSFTextParagraph para = shape.addNewTextParagraph();
+
+            // 1. Obtain or create the underlying XML structure
+            CTTextParagraph ctPara = para.getXmlObject();
+            CTTextParagraphProperties pr = ctPara.isSetPPr() ? ctPara.getPPr() : ctPara.addNewPPr();
+
+            // 2. Force a level to avoid ParagraphPropertyFetcher errors
+            pr.setLvl(0);
+
+            // 3. Set an out-of-range autonumber type (e.g. 24)
+            CTTextAutonumberBullet bullet = pr.isSetBuAutoNum() ? pr.getBuAutoNum() : pr.addNewBuAutoNum();
+            bullet.setType(STTextAutonumberScheme.Enum.forInt(24));
+
+            // 4. Execute the test
+            // If you haven't applied the fix, this line will throw AIOOBE
+            // If the fix is applied, this should return ARABIC_PLAIN
+            ListAutoNumber result = para.getBulletAutoNumberScheme();
+
+            assertNotNull(result, "Result should not be null");
+            assertEquals(ListAutoNumber.ARABIC_PLAIN, result, "Should fallback to ARABIC_PLAIN for unknown index");
+        } catch (Exception e) {

Review Comment:
   Done. I've updated the test case to throw exceptions directly and removed the catch block. Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org