Hi Alex, Thanks for the prompt reply. The stack trace shows openOutputStream(File, boolean) which is called by FileUtils.write(File, charsequence). Thanks for the pointers. I will keep you posted.
Best, Abhishek On Mon, Oct 17, 2022 at 4:08 PM Alex Herbert <[email protected]> wrote: > The documentation for File.isFile [1] reads: > > "Tests whether the file denoted by this abstract pathname is a normal > file." > > /dev/null is not a normal file. It is a special file used to write > bytes without error. So use of this file would be under special > circumstances and is not something expected for the common use case of > FileUtils. > > Note that you can write to this file using the latest master version > of IO (2.12.0-SNAPSHOT) since this works (and prints false): > > @Test > void testDevNull() throws IOException { > File f = new File("/dev/null"); > System.out.println(f.isFile()); > FileUtils.write(f, "hello", StandardCharsets.UTF_8); > } > > So this is not the source of error in your test. > > You mention the error is raised in the method FileUtils.requireFile. > This is a private method that is used in the following public methods: > > checksum(File, Checksum) > contentEquals(File, File) > contentEqualsIgnoreEOL(File, File, String) > copyFile(File, File, CopOption...) > moveFile(File, File, CopOption...) > openOutputStream(File, boolean) > > So perhaps you are using one of these methods (or one that calls them) > in your tests. You should be able to view the stacktrace and see the > origin of the error. If your test is using /dev/null as a sink for > data that you do not care about then in this case you can create a > temp file in your test and use that as your destination. Then delete > your temp file at the end of the test. This will at least ensure that > all bytes are consumed by the destination file, even if you do not > wish to validate that in your test. > > If you have code that wishes to output to a file or optionally ignore > output then you can use one of the objects that acts like /dev/null, > e.g. NullAppendable, NullOutputStream, NullPrintStream or NullWriter. > > Regards, > > Alex > > [1] https://docs.oracle.com/javase/8/docs/api/java/io/File.html#isFile-- > > On Mon, 17 Oct 2022 at 10:45, ABHISHEK DAS GUPTA <[email protected]> > wrote: > > > > Hello, > > We are currently addressing commons io CVE where we need to upgrade it > > from 2.4 to 2.11.0 . After the upgrade, one of our UTs is failing with > > "Parameter 'file' is not a file: /dev/null" . Within the codeflow of the > > test there is a call to FileUtils.write( File("/dev/null"), char > sequence) > > and the code fails here after this method call. We digged inside the > > internal of this method and analyzed the difference b/w 2.4 and 2.11.0. > > There is a difference b/w the flow and we traced it back to the following > > commit. > > < > https://github.com/apache/commons-io/commit/0cee29aa4c1818963ed1a55058219282e89d7488?diff=split > > > > There > > is a check > > < > https://github.com/apache/commons-io/blob/7264b2607235065aef98f12ee0e3c0d3586b9b49/src/main/java/org/apache/commons/io/FileUtils.java#L2809 > > > > to see whether /dev/null is a file or not. This returns false. > > Please let us know how to proceed to fix this issue and if you can > provide > > a reason also why this is failing? > > > > Best > > Abhishek > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
