0

I am running a unit test in an Eclipse project, and when I run the following JUnit test

@Before
public void setup() {
    final byte[] array = IOUtils.byteArray();
    ...
}

I get the following error:

java.lang.NoSuchMethodError: org.apache.commons.io.IOUtils.byteArray()[B

I have included Apache commons-io 2.11.0 in my classpath:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
... 
    <classpathentry kind="var" path="APACHE_IO/commons-io-2.11.0/commons-io-2.11.0.jar"/>
... 
</classpath>

What am I missing here?

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • 2
    Maybe you shouldn’t use a third party library, just to obfuscate the expression `new byte[8192]` as `IOUtils.byteArray()`. – Holger Aug 25 '22 at 16:21
  • 1
    Have you verified that the class in that jar has that method and signature? – nitind Aug 25 '22 at 18:11
  • The issue is that methods in Apache POI use IOUtils.byteArray; the only reason that I put it into setup() is to test the existence of byteArray(). – David Gauntt Aug 25 '22 at 19:41
  • I have verified that the jar file contains IOUtils.class, and that the sources jar file contains IOUtils.java, and that IOUtils.java contains byteArray(). I have imported the java file into my project, and it worked. It looks like IOUtils.class may have been built from a different version of IOUtils.java; I will report this as a bug to Apache. – David Gauntt Aug 25 '22 at 19:50
  • 1
    Hey @DavidGauntt I have run into the same issue now, did you find a work-around? – beria Nov 25 '22 at 10:19

0 Answers0