[ https://issues.apache.org/jira/browse/VFS-724?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16904186#comment-16904186 ]
William Rey commented on VFS-724: --------------------------------- I have added the following test in {{org.apache.commons.vfs2.provider.http4.test.Http4GetContentInfoTest}} {code:java} @Test public void testGetZeroContents() throws IOException { final FileSystemManager fsManager = VFS.getManager(); final FileObject fo = fsManager.resolveFile("http4://monpremierlivre.home.blog/"); final FileContent content = fo.getContent(); Assert.assertNotNull(content.getString(StandardCharsets.UTF_8)); // Used to NPE before fix: content.getContentInfo(); } {code} and fails with the following: {code} java.lang.IllegalArgumentException: Buffer size <= 0 at java.io.BufferedInputStream.<init>(BufferedInputStream.java:201) at org.apache.commons.vfs2.util.MonitorInputStream.<init>(MonitorInputStream.java:51) at org.apache.commons.vfs2.provider.DefaultFileContent$FileContentInputStream.<init>(DefaultFileContent.java:619) at org.apache.commons.vfs2.provider.DefaultFileContent.buildInputStream(DefaultFileContent.java:499) at org.apache.commons.vfs2.provider.DefaultFileContent.getInputStream(DefaultFileContent.java:356) at org.apache.commons.vfs2.FileContent.getByteArray(FileContent.java:134) at org.apache.commons.vfs2.FileContent.getString(FileContent.java:283) at org.apache.commons.vfs2.provider.http4.test.Http4GetContentInfoTest.testGetZeroContents(Http4GetContentInfoTest.java:73) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at junit.framework.TestCase.runTest(TestCase.java:176) at junit.framework.TestCase.runBare(TestCase.java:141) at junit.framework.TestResult$1.protect(TestResult.java:122) at junit.framework.TestResult.runProtected(TestResult.java:142) at junit.framework.TestResult.run(TestResult.java:125) at junit.framework.TestCase.run(TestCase.java:129) at junit.framework.TestSuite.runTest(TestSuite.java:252) at junit.framework.TestSuite.run(TestSuite.java:247) at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) {code} Note the page requested is a Wordpress generated-page (not a static one) then the {Content-length}} is zero (not given) then of course trying to read in an empty buffer raises an exception. I don't know the best way to fix it. I try to open an issue in GitHub with a fix. > FileContentt#getByteArray() throw Exception > ------------------------------------------- > > Key: VFS-724 > URL: https://issues.apache.org/jira/browse/VFS-724 > Project: Commons VFS > Issue Type: Bug > Affects Versions: 2.4 > Reporter: William Rey > Priority: Major > > The current code only checks for a size bigger than 2MB but ignores when the > returned size is 0 or negative. {{sizeL}} will be typically equals to zero if > the request is made to a WebServer and the response generated live (like > PHP). Then the {{getInputStream(size)}} will fail in this case when the size > is really used by the implementation. > {code} > default byte[] getByteArray() throws IOException { > final long sizeL = getSize(); > if (sizeL > Integer.MAX_VALUE) { > throw new IllegalStateException(String.format("File content is > too large for a byte array: %,d", sizeL)); > } > {code} -- This message was sent by Atlassian JIRA (v7.6.14#76016)