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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With