35

I have upgraded from org.apache.poi-poi-ooxml-5.2.3 to org.apache.poi-poi-ooxml-5.2.4 due to Security Violation Threat in 5.2.3

Now, I am facing run time exception as java.lang.NoSuchMethodError

Exception:

[ERROR] ErrorPageFilter - Forwarding to error page from request [/reports/myapp/myreport] due to exception ['org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream$Builder org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream.builder()']
java.lang.NoSuchMethodError: 'org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream$Builder org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream.builder()'
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.newPackage(XSSFWorkbook.java:521) ~[poi-ooxml-5.2.4.jar:5.2.4]
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:231) ~[poi-ooxml-5.2.4.jar:5.2.4]
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:227) ~[poi-ooxml-5.2.4.jar:5.2.4]
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:215) ~[poi-ooxml-5.2.4.jar:5.2.4]
    at myapp.reports.service.impl.MyReportsExcelExporter.<init>(MyReportsExcelExporter.java:37) ~[classes/:0.0.1-SNAPSHOT]

Code:

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class MyReportsExcelExporter {
    protected XSSFWorkbook workbook;
    ...
    public MyReportsExcelExporter() {
        this.workbook = new XSSFWorkbook(); //Facing issue here, while initializing the workbook.
    }
    ...
}

Looking at the version change, it seems like a minor upgrade but now existing code has stopped working.

What's probably wrong?

0

2 Answers 2

44

You will need to add/upgrade Apache Commons IO dependency version >= 2.12.0.

Note: The builder() method present in UnsynchronizedByteArrayOutputStream class got introduced from 2.12.0 version of commons-io onwards.

I took the latest dependency of commons-io which is 2.14.0 at the time of writing the answer.

pom.xml (Maven):

<dependencies>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.14.0</version>
    </dependency>
</dependencies>

build.gradle (Gradle):

dependencies {
   implementation 'commons-io:commons-io:2.14.0'
}

It will work.

8
  • 1
    Currently using commons-io 2.11.0
    – Prem
    Commented Oct 9, 2023 at 7:03
  • 2
    Working after upgrading commons-io 2.11.0 to 2.14.0 As UnsynchronizedByteArrayOutputStream.builder() is not available in commons-io 2.11.0
    – Prem
    Commented Oct 9, 2023 at 7:25
  • 1
    What POI 5.2.4 docs say you should use ancient commons-io versions? poi.apache.org/changes.html lists the upgrade to commons-io 2.13.0 but 2.14.0 is ok too. If you provide a link to the incorrect docs, we can fix them.
    – PJ Fanning
    Commented Oct 9, 2023 at 11:05
  • 2
    @AnishB., I think is should not be version >=2.7.x it should be version >= 2.14.0. Not sure when was UnsynchronizedByteArrayOutputStream.builder() introduced. Could you please confirm?
    – Prem
    Commented Oct 10, 2023 at 7:54
  • 1
    Happened also using org.apache.tika:tika-core:3.1.0 solved as suggested.
    – lrkwz
    Commented Mar 5 at 18:28
6

just playing with versions of poi worked out for me, downgraded to the 5.2.2 from 5.2.5 version worked out

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>5.2.2</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>5.2.2</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml-schemas</artifactId>
        <version>4.1.2</version>
        <scope>compile</scope>
    </dependency>

is what my pom looks like

3
  • 1
    It is rare day that a -1 comment from a new account is a working answer, and today is that day! Thank you! Commented Oct 16, 2024 at 4:10
  • 1
    Its truly that day @DylanKnowles. Tried everything but got it working with this method. so thanks buddy.
    – SourabhS
    Commented Dec 3, 2024 at 17:25
  • playing with version worked for me as well, Thanks Commented Dec 17, 2024 at 15:31

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.