[jira] [Commented] (IO-809) MessageDigestCalculatingInputStream Builder Not Working
[ https://issues.apache.org/jira/browse/IO-809?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17769945#comment-17769945 ] Gregor Dschung commented on IO-809: --- Ups, of course! Sorry for my superfluous comment... > MessageDigestCalculatingInputStream Builder Not Working > --- > > Key: IO-809 > URL: https://issues.apache.org/jira/browse/IO-809 > Project: Commons IO > Issue Type: Bug >Affects Versions: 2.12.0, 2.13.0 >Reporter: Jeremias Eppler >Priority: Major > Fix For: 3.x > > Attachments: commons-io-issue.png > > > I am currently trying to use the MessageDigestCalculatingInputStream Builder. > However, the setters of the builder do not return the builder. > Meaning, this code does not work: > > ~~~java > MessageDigestCalculatingInputStream messageDigestInputStream = > MessageDigestCalculatingInputStream.builder() > .setInputStream(fileInputstream) > .setMessageDigest(digest) > .get(); > ~~~ -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Updated] (IO-810) Wrong Javadoc regarding FileNotFoundException in FileUtils
[ https://issues.apache.org/jira/browse/IO-810?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Gregor Dschung updated IO-810: -- Summary: Wrong Javadoc regarding FileNotFoundException in FileUtils (was: Wrong JavaDoc regarding FileNotFoundException in FileUtils) > Wrong Javadoc regarding FileNotFoundException in FileUtils > -- > > Key: IO-810 > URL: https://issues.apache.org/jira/browse/IO-810 > Project: Commons IO > Issue Type: Bug > Components: Utilities >Affects Versions: 2.12.0, 2.13.0 >Reporter: Gregor Dschung >Priority: Major > > The JavaDoc of {{FileUtils#readFileToString(...)}} is stating that a > {{FileNotFoundException}} is thrown if the file doesn't exist. This isn't > true with version 2.12 and above, including the current 2.14 snapshot, where > a {{NoSuchFileException}} is thrown. I haven't tested, but I guess that other > methods like {{FileUtils#readFileToByteArray(...)}} are affected, too, as the > exception is coming via {{Files#newByteChannel(...)}}. > Root cause seems to be, like in IO-800, [this > commit|https://github.com/apache/commons-io/commit/dcb09db922e1edbd6dc6cb1531b827451d58aa83#diff-0bd8160a11e12ea1f96476a00e78d0a95b965d07c7fe126e1af498c08511dd70] > from 2021, where {{openInputStream(file)}} (which is calling > {{new FileInputStream(file)}} from {{java.io}}) is replaced by > {{Files.newInputStream(file.toPath())}} from {{java.nio}}. > I'm unsure if just the JavaDoc should be updated or the old behavior be > restored: I noticed the bug because we catch a {{FileNotFoundException}}, > which doesn't work for 2.12 and above. > {code:title=Old Stacktrace} > java.io.FileNotFoundException: doesnt-exist.txt (No such file or directory) > at java.base/java.io.FileInputStream.open0(Native Method) ~[na:na] > at java.base/java.io.FileInputStream.open(FileInputStream.java:219) > ~[na:na] > at java.base/java.io.FileInputStream.(FileInputStream.java:157) > ~[na:na] > at org.apache.commons.io.FileUtils.openInputStream(FileUtils.java:2388) > ~[commons-io-2.11.0.jar:2.11.0] > at > org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2506) > ~[commons-io-2.11.0.jar:2.11.0] > at > org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2526) > ~[commons-io-2.11.0.jar:2.11.0] > {code} > {code:title=New Stacktrace} > java.nio.file.NoSuchFileException: doesnt-exist.txt > at > java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92) > ~[na:na] > at > java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) > ~[na:na] > at > java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116) > ~[na:na] > at > java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:219) > ~[na:na] > at java.base/java.nio.file.Files.newByteChannel(Files.java:371) ~[na:na] > at java.base/java.nio.file.Files.newByteChannel(Files.java:422) ~[na:na] > at > java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420) > ~[na:na] > at java.base/java.nio.file.Files.newInputStream(Files.java:156) ~[na:na] > at > org.apache.commons.io.FileUtils.lambda$readFileToString$12(FileUtils.java:2616) > ~[commons-io-2.13.0.jar:2.13.0] > at org.apache.commons.io.IOUtils.toString(IOUtils.java:3177) > ~[commons-io-2.13.0.jar:2.13.0] > at org.apache.commons.io.IOUtils.toString(IOUtils.java:3152) > ~[commons-io-2.13.0.jar:2.13.0] > at > org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2616) > ~[commons-io-2.13.0.jar:2.13.0] > at > org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2599) > ~[commons-io-2.13.0.jar:2.13.0] > {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Updated] (IO-810) Wrong JavaDoc regarding FileNotFoundException in FileUtils
[ https://issues.apache.org/jira/browse/IO-810?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Gregor Dschung updated IO-810: -- Summary: Wrong JavaDoc regarding FileNotFoundException in FileUtils (was: Wrong JavaDoc regarding exception in FileUtils) > Wrong JavaDoc regarding FileNotFoundException in FileUtils > -- > > Key: IO-810 > URL: https://issues.apache.org/jira/browse/IO-810 > Project: Commons IO > Issue Type: Bug > Components: Utilities >Affects Versions: 2.12.0, 2.13.0 >Reporter: Gregor Dschung >Priority: Major > > The JavaDoc of {{FileUtils#readFileToString(...)}} is stating that a > {{FileNotFoundException}} is thrown if the file doesn't exist. This isn't > true with version 2.12 and above, including the current 2.14 snapshot, where > a {{NoSuchFileException}} is thrown. I haven't tested, but I guess that other > methods like {{FileUtils#readFileToByteArray(...)}} are affected, too, as the > exception is coming via {{Files#newByteChannel(...)}}. > Root cause seems to be, like in IO-800, [this > commit|https://github.com/apache/commons-io/commit/dcb09db922e1edbd6dc6cb1531b827451d58aa83#diff-0bd8160a11e12ea1f96476a00e78d0a95b965d07c7fe126e1af498c08511dd70] > from 2021, where {{openInputStream(file)}} (which is calling > {{new FileInputStream(file)}} from {{java.io}}) is replaced by > {{Files.newInputStream(file.toPath())}} from {{java.nio}}. > I'm unsure if just the JavaDoc should be updated or the old behavior be > restored: I noticed the bug because we catch a {{FileNotFoundException}}, > which doesn't work for 2.12 and above. > {code:title=Old Stacktrace} > java.io.FileNotFoundException: doesnt-exist.txt (No such file or directory) > at java.base/java.io.FileInputStream.open0(Native Method) ~[na:na] > at java.base/java.io.FileInputStream.open(FileInputStream.java:219) > ~[na:na] > at java.base/java.io.FileInputStream.(FileInputStream.java:157) > ~[na:na] > at org.apache.commons.io.FileUtils.openInputStream(FileUtils.java:2388) > ~[commons-io-2.11.0.jar:2.11.0] > at > org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2506) > ~[commons-io-2.11.0.jar:2.11.0] > at > org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2526) > ~[commons-io-2.11.0.jar:2.11.0] > {code} > {code:title=New Stacktrace} > java.nio.file.NoSuchFileException: doesnt-exist.txt > at > java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92) > ~[na:na] > at > java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) > ~[na:na] > at > java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116) > ~[na:na] > at > java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:219) > ~[na:na] > at java.base/java.nio.file.Files.newByteChannel(Files.java:371) ~[na:na] > at java.base/java.nio.file.Files.newByteChannel(Files.java:422) ~[na:na] > at > java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420) > ~[na:na] > at java.base/java.nio.file.Files.newInputStream(Files.java:156) ~[na:na] > at > org.apache.commons.io.FileUtils.lambda$readFileToString$12(FileUtils.java:2616) > ~[commons-io-2.13.0.jar:2.13.0] > at org.apache.commons.io.IOUtils.toString(IOUtils.java:3177) > ~[commons-io-2.13.0.jar:2.13.0] > at org.apache.commons.io.IOUtils.toString(IOUtils.java:3152) > ~[commons-io-2.13.0.jar:2.13.0] > at > org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2616) > ~[commons-io-2.13.0.jar:2.13.0] > at > org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2599) > ~[commons-io-2.13.0.jar:2.13.0] > {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Comment Edited] (IO-809) MessageDigestCalculatingInputStream Builder Not Working
[ https://issues.apache.org/jira/browse/IO-809?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17769604#comment-17769604 ] Gregor Dschung edited comment on IO-809 at 9/27/23 1:30 PM: As the current signature returns void, there shouldn't be any assignments to variables out there. So it wouldn't be a breaking change, or am I overlooking something? UPDATE: Ah, I see, it's a non-final public class, so subclassing would be an issue. But seriously: Who would do that in this case? And as the JavaDoc is stating that a fluent-api is possible, I think we shouldn't wait for a major version to update the current implementation. was (Author: JIRAUSER302379): As the current signature returns void, there shouldn't be any assignments to variables out there. So it wouldn't be a breaking change, or am I overlooking something? UPDATE: Ah, I see, it's a non-final public class, so subclassing would be an issue. But seriously: Who would do that in this case? And as the JavaDoc is stating, that a fluent-api is possible, I think we shouldn't wait for a major version to update the current implementation. > MessageDigestCalculatingInputStream Builder Not Working > --- > > Key: IO-809 > URL: https://issues.apache.org/jira/browse/IO-809 > Project: Commons IO > Issue Type: Bug >Affects Versions: 2.12.0, 2.13.0 >Reporter: Jeremias Eppler >Priority: Major > Fix For: 3.x > > Attachments: commons-io-issue.png > > > I am currently trying to use the MessageDigestCalculatingInputStream Builder. > However, the setters of the builder do not return the builder. > Meaning, this code does not work: > > ~~~java > MessageDigestCalculatingInputStream messageDigestInputStream = > MessageDigestCalculatingInputStream.builder() > .setInputStream(fileInputstream) > .setMessageDigest(digest) > .get(); > ~~~ -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Comment Edited] (IO-809) MessageDigestCalculatingInputStream Builder Not Working
[ https://issues.apache.org/jira/browse/IO-809?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17769604#comment-17769604 ] Gregor Dschung edited comment on IO-809 at 9/27/23 1:29 PM: As the current signature returns void, there shouldn't be any assignments to variables out there. So it wouldn't be a breaking change, or am I overlooking something? UPDATE: Ah, I see, it's a non-final public class, so subclassing would be an issue. But seriously: Who would do that in this case? And as the JavaDoc is stating, that a fluent-api is possible, I think we shouldn't wait for a major version to update the current implementation. was (Author: JIRAUSER302379): As the current signature returns void, there shouldn't be any assignments to variables out there. So it wouldn't be a breaking change, or am I overlooking something? > MessageDigestCalculatingInputStream Builder Not Working > --- > > Key: IO-809 > URL: https://issues.apache.org/jira/browse/IO-809 > Project: Commons IO > Issue Type: Bug >Affects Versions: 2.12.0, 2.13.0 >Reporter: Jeremias Eppler >Priority: Major > Fix For: 3.x > > Attachments: commons-io-issue.png > > > I am currently trying to use the MessageDigestCalculatingInputStream Builder. > However, the setters of the builder do not return the builder. > Meaning, this code does not work: > > ~~~java > MessageDigestCalculatingInputStream messageDigestInputStream = > MessageDigestCalculatingInputStream.builder() > .setInputStream(fileInputstream) > .setMessageDigest(digest) > .get(); > ~~~ -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (IO-809) MessageDigestCalculatingInputStream Builder Not Working
[ https://issues.apache.org/jira/browse/IO-809?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17769604#comment-17769604 ] Gregor Dschung commented on IO-809: --- As the current signature returns void, there shouldn't be any assignments to variables out there. So it wouldn't be a breaking change, or am I overlooking something? > MessageDigestCalculatingInputStream Builder Not Working > --- > > Key: IO-809 > URL: https://issues.apache.org/jira/browse/IO-809 > Project: Commons IO > Issue Type: Bug >Affects Versions: 2.12.0, 2.13.0 >Reporter: Jeremias Eppler >Priority: Major > Fix For: 3.x > > Attachments: commons-io-issue.png > > > I am currently trying to use the MessageDigestCalculatingInputStream Builder. > However, the setters of the builder do not return the builder. > Meaning, this code does not work: > > ~~~java > MessageDigestCalculatingInputStream messageDigestInputStream = > MessageDigestCalculatingInputStream.builder() > .setInputStream(fileInputstream) > .setMessageDigest(digest) > .get(); > ~~~ -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Comment Edited] (IO-810) Wrong JavaDoc regarding exception in FileUtils
[ https://issues.apache.org/jira/browse/IO-810?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17769596#comment-17769596 ] Gregor Dschung edited comment on IO-810 at 9/27/23 1:12 PM: Okay, I'll do so. I see two options: # As {{NoSuchFileException}} is an {{IOException}}, the simplest and most future-proof way would be to just remove {{FileNotFoundException}} from the JavaDoc and instead to change the description of {{IOException}} to something like {{@throws IOException if an I/O error occurs, including when the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading.}}. # Or do you prefer to keep the exception for the file-doesn't-exist-case explicit? was (Author: JIRAUSER302379): Okay, I'll do so. I see two options: # As {{NoSuchFileException}} is an {{IOException}}, the simplest and most future-proof way would be to just remove {{FileNotFoundException}} from the JavaDoc and instead to change the description of {{NoSuchFileException}} to something like {{@throws IOException if an I/O error occurs, including when the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading.}}. # Or do you prefer to keep the exception for the file-doesn't-exist-case explicit? > Wrong JavaDoc regarding exception in FileUtils > -- > > Key: IO-810 > URL: https://issues.apache.org/jira/browse/IO-810 > Project: Commons IO > Issue Type: Bug > Components: Utilities >Affects Versions: 2.12.0, 2.13.0 >Reporter: Gregor Dschung >Priority: Major > > The JavaDoc of {{FileUtils#readFileToString(...)}} is stating that a > {{FileNotFoundException}} is thrown if the file doesn't exist. This isn't > true with version 2.12 and above, including the current 2.14 snapshot, where > a {{NoSuchFileException}} is thrown. I haven't tested, but I guess that other > methods like {{FileUtils#readFileToByteArray(...)}} are affected, too, as the > exception is coming via {{Files#newByteChannel(...)}}. > Root cause seems to be, like in IO-800, [this > commit|https://github.com/apache/commons-io/commit/dcb09db922e1edbd6dc6cb1531b827451d58aa83#diff-0bd8160a11e12ea1f96476a00e78d0a95b965d07c7fe126e1af498c08511dd70] > from 2021, where {{openInputStream(file)}} (which is calling > {{new FileInputStream(file)}} from {{java.io}}) is replaced by > {{Files.newInputStream(file.toPath())}} from {{java.nio}}. > I'm unsure if just the JavaDoc should be updated or the old behavior be > restored: I noticed the bug because we catch a {{FileNotFoundException}}, > which doesn't work for 2.12 and above. > {code:title=Old Stacktrace} > java.io.FileNotFoundException: doesnt-exist.txt (No such file or directory) > at java.base/java.io.FileInputStream.open0(Native Method) ~[na:na] > at java.base/java.io.FileInputStream.open(FileInputStream.java:219) > ~[na:na] > at java.base/java.io.FileInputStream.(FileInputStream.java:157) > ~[na:na] > at org.apache.commons.io.FileUtils.openInputStream(FileUtils.java:2388) > ~[commons-io-2.11.0.jar:2.11.0] > at > org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2506) > ~[commons-io-2.11.0.jar:2.11.0] > at > org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2526) > ~[commons-io-2.11.0.jar:2.11.0] > {code} > {code:title=New Stacktrace} > java.nio.file.NoSuchFileException: doesnt-exist.txt > at > java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92) > ~[na:na] > at > java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) > ~[na:na] > at > java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116) > ~[na:na] > at > java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:219) > ~[na:na] > at java.base/java.nio.file.Files.newByteChannel(Files.java:371) ~[na:na] > at java.base/java.nio.file.Files.newByteChannel(Files.java:422) ~[na:na] > at > java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420) > ~[na:na] > at java.base/java.nio.file.Files.newInputStream(Files.java:156) ~[na:na] > at > org.apache.commons.io.FileUtils.lambda$readFileToString$12(FileUtils.java:2616) > ~[commons-io-2.13.0.jar:2.13.0] > at org.apache.commons.io.IOUtils.toString(IOUtils.java:3177) > ~[commons-io-2.13.0.jar:2.13.0] > at org.apache.commons.io.IOUtils.toString(IOUtils.java:3152) > ~[commons-io-2.13.0.jar:2.13.0] > at > org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2616) > ~[commons-io-2.13.0.jar:2.13.0] > at > org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2599) >
[jira] [Commented] (IO-810) Wrong JavaDoc regarding exception in FileUtils
[ https://issues.apache.org/jira/browse/IO-810?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17769596#comment-17769596 ] Gregor Dschung commented on IO-810: --- Okay, I'll do so. I see two options: # As {{NoSuchFileException}} is an {{IOException}}, the simplest and most future-proof way would be to just remove {{FileNotFoundException}} from the JavaDoc and instead to change the description of {{NoSuchFileException}} to something like {{@throws IOException if an I/O error occurs, including when the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading.}}. # Or do you prefer to keep the exception for the file-doesn't-exist-case explicit? > Wrong JavaDoc regarding exception in FileUtils > -- > > Key: IO-810 > URL: https://issues.apache.org/jira/browse/IO-810 > Project: Commons IO > Issue Type: Bug > Components: Utilities >Affects Versions: 2.12.0, 2.13.0 >Reporter: Gregor Dschung >Priority: Major > > The JavaDoc of {{FileUtils#readFileToString(...)}} is stating that a > {{FileNotFoundException}} is thrown if the file doesn't exist. This isn't > true with version 2.12 and above, including the current 2.14 snapshot, where > a {{NoSuchFileException}} is thrown. I haven't tested, but I guess that other > methods like {{FileUtils#readFileToByteArray(...)}} are affected, too, as the > exception is coming via {{Files#newByteChannel(...)}}. > Root cause seems to be, like in IO-800, [this > commit|https://github.com/apache/commons-io/commit/dcb09db922e1edbd6dc6cb1531b827451d58aa83#diff-0bd8160a11e12ea1f96476a00e78d0a95b965d07c7fe126e1af498c08511dd70] > from 2021, where {{openInputStream(file)}} (which is calling > {{new FileInputStream(file)}} from {{java.io}}) is replaced by > {{Files.newInputStream(file.toPath())}} from {{java.nio}}. > I'm unsure if just the JavaDoc should be updated or the old behavior be > restored: I noticed the bug because we catch a {{FileNotFoundException}}, > which doesn't work for 2.12 and above. > {code:title=Old Stacktrace} > java.io.FileNotFoundException: doesnt-exist.txt (No such file or directory) > at java.base/java.io.FileInputStream.open0(Native Method) ~[na:na] > at java.base/java.io.FileInputStream.open(FileInputStream.java:219) > ~[na:na] > at java.base/java.io.FileInputStream.(FileInputStream.java:157) > ~[na:na] > at org.apache.commons.io.FileUtils.openInputStream(FileUtils.java:2388) > ~[commons-io-2.11.0.jar:2.11.0] > at > org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2506) > ~[commons-io-2.11.0.jar:2.11.0] > at > org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2526) > ~[commons-io-2.11.0.jar:2.11.0] > {code} > {code:title=New Stacktrace} > java.nio.file.NoSuchFileException: doesnt-exist.txt > at > java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92) > ~[na:na] > at > java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) > ~[na:na] > at > java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116) > ~[na:na] > at > java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:219) > ~[na:na] > at java.base/java.nio.file.Files.newByteChannel(Files.java:371) ~[na:na] > at java.base/java.nio.file.Files.newByteChannel(Files.java:422) ~[na:na] > at > java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420) > ~[na:na] > at java.base/java.nio.file.Files.newInputStream(Files.java:156) ~[na:na] > at > org.apache.commons.io.FileUtils.lambda$readFileToString$12(FileUtils.java:2616) > ~[commons-io-2.13.0.jar:2.13.0] > at org.apache.commons.io.IOUtils.toString(IOUtils.java:3177) > ~[commons-io-2.13.0.jar:2.13.0] > at org.apache.commons.io.IOUtils.toString(IOUtils.java:3152) > ~[commons-io-2.13.0.jar:2.13.0] > at > org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2616) > ~[commons-io-2.13.0.jar:2.13.0] > at > org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2599) > ~[commons-io-2.13.0.jar:2.13.0] > {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Created] (IO-810) Wrong JavaDoc regarding exception in FileUtils
Gregor Dschung created IO-810: - Summary: Wrong JavaDoc regarding exception in FileUtils Key: IO-810 URL: https://issues.apache.org/jira/browse/IO-810 Project: Commons IO Issue Type: Bug Components: Utilities Affects Versions: 2.13.0, 2.12.0 Reporter: Gregor Dschung The JavaDoc of {{FileUtils#readFileToString(...)}} is stating that a {{FileNotFoundException}} is thrown if the file doesn't exist. This isn't true with version 2.12 and above, including the current 2.14 snapshot, where a {{NoSuchFileException}} is thrown. I haven't tested, but I guess that other methods like {{FileUtils#readFileToByteArray(...)}} are affected, too, as the exception is coming via {{Files#newByteChannel(...)}}. Root cause seems to be, like in IO-800, [this commit|https://github.com/apache/commons-io/commit/dcb09db922e1edbd6dc6cb1531b827451d58aa83#diff-0bd8160a11e12ea1f96476a00e78d0a95b965d07c7fe126e1af498c08511dd70] from 2021, where {{openInputStream(file)}} (which is calling {{new FileInputStream(file)}} from {{java.io}}) is replaced by Files.newInputStream(file.toPath()) from {{java.nio}}. I'm unsure if just the JavaDoc should be updated or the old behavior be restored: I noticed the bug because we catch a {{FileNotFoundException}}, which doesn't work for 2.12 and above. {code:title=Old Stacktrace} java.io.FileNotFoundException: doesnt-exist.txt (No such file or directory) at java.base/java.io.FileInputStream.open0(Native Method) ~[na:na] at java.base/java.io.FileInputStream.open(FileInputStream.java:219) ~[na:na] at java.base/java.io.FileInputStream.(FileInputStream.java:157) ~[na:na] at org.apache.commons.io.FileUtils.openInputStream(FileUtils.java:2388) ~[commons-io-2.11.0.jar:2.11.0] at org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2506) ~[commons-io-2.11.0.jar:2.11.0] at org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2526) ~[commons-io-2.11.0.jar:2.11.0] {code} {code:title=New Stacktrace} java.nio.file.NoSuchFileException: doesnt-exist.txt at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92) ~[na:na] at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) ~[na:na] at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116) ~[na:na] at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:219) ~[na:na] at java.base/java.nio.file.Files.newByteChannel(Files.java:371) ~[na:na] at java.base/java.nio.file.Files.newByteChannel(Files.java:422) ~[na:na] at java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420) ~[na:na] at java.base/java.nio.file.Files.newInputStream(Files.java:156) ~[na:na] at org.apache.commons.io.FileUtils.lambda$readFileToString$12(FileUtils.java:2616) ~[commons-io-2.13.0.jar:2.13.0] at org.apache.commons.io.IOUtils.toString(IOUtils.java:3177) ~[commons-io-2.13.0.jar:2.13.0] at org.apache.commons.io.IOUtils.toString(IOUtils.java:3152) ~[commons-io-2.13.0.jar:2.13.0] at org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2616) ~[commons-io-2.13.0.jar:2.13.0] at org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2599) ~[commons-io-2.13.0.jar:2.13.0] {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Updated] (IO-810) Wrong JavaDoc regarding exception in FileUtils
[ https://issues.apache.org/jira/browse/IO-810?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Gregor Dschung updated IO-810: -- Description: The JavaDoc of {{FileUtils#readFileToString(...)}} is stating that a {{FileNotFoundException}} is thrown if the file doesn't exist. This isn't true with version 2.12 and above, including the current 2.14 snapshot, where a {{NoSuchFileException}} is thrown. I haven't tested, but I guess that other methods like {{FileUtils#readFileToByteArray(...)}} are affected, too, as the exception is coming via {{Files#newByteChannel(...)}}. Root cause seems to be, like in IO-800, [this commit|https://github.com/apache/commons-io/commit/dcb09db922e1edbd6dc6cb1531b827451d58aa83#diff-0bd8160a11e12ea1f96476a00e78d0a95b965d07c7fe126e1af498c08511dd70] from 2021, where {{openInputStream(file)}} (which is calling {{new FileInputStream(file)}} from {{java.io}}) is replaced by {{Files.newInputStream(file.toPath())}} from {{java.nio}}. I'm unsure if just the JavaDoc should be updated or the old behavior be restored: I noticed the bug because we catch a {{FileNotFoundException}}, which doesn't work for 2.12 and above. {code:title=Old Stacktrace} java.io.FileNotFoundException: doesnt-exist.txt (No such file or directory) at java.base/java.io.FileInputStream.open0(Native Method) ~[na:na] at java.base/java.io.FileInputStream.open(FileInputStream.java:219) ~[na:na] at java.base/java.io.FileInputStream.(FileInputStream.java:157) ~[na:na] at org.apache.commons.io.FileUtils.openInputStream(FileUtils.java:2388) ~[commons-io-2.11.0.jar:2.11.0] at org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2506) ~[commons-io-2.11.0.jar:2.11.0] at org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2526) ~[commons-io-2.11.0.jar:2.11.0] {code} {code:title=New Stacktrace} java.nio.file.NoSuchFileException: doesnt-exist.txt at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92) ~[na:na] at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) ~[na:na] at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116) ~[na:na] at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:219) ~[na:na] at java.base/java.nio.file.Files.newByteChannel(Files.java:371) ~[na:na] at java.base/java.nio.file.Files.newByteChannel(Files.java:422) ~[na:na] at java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420) ~[na:na] at java.base/java.nio.file.Files.newInputStream(Files.java:156) ~[na:na] at org.apache.commons.io.FileUtils.lambda$readFileToString$12(FileUtils.java:2616) ~[commons-io-2.13.0.jar:2.13.0] at org.apache.commons.io.IOUtils.toString(IOUtils.java:3177) ~[commons-io-2.13.0.jar:2.13.0] at org.apache.commons.io.IOUtils.toString(IOUtils.java:3152) ~[commons-io-2.13.0.jar:2.13.0] at org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2616) ~[commons-io-2.13.0.jar:2.13.0] at org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2599) ~[commons-io-2.13.0.jar:2.13.0] {code} was: The JavaDoc of {{FileUtils#readFileToString(...)}} is stating that a {{FileNotFoundException}} is thrown if the file doesn't exist. This isn't true with version 2.12 and above, including the current 2.14 snapshot, where a {{NoSuchFileException}} is thrown. I haven't tested, but I guess that other methods like {{FileUtils#readFileToByteArray(...)}} are affected, too, as the exception is coming via {{Files#newByteChannel(...)}}. Root cause seems to be, like in IO-800, [this commit|https://github.com/apache/commons-io/commit/dcb09db922e1edbd6dc6cb1531b827451d58aa83#diff-0bd8160a11e12ea1f96476a00e78d0a95b965d07c7fe126e1af498c08511dd70] from 2021, where {{openInputStream(file)}} (which is calling {{new FileInputStream(file)}} from {{java.io}}) is replaced by Files.newInputStream(file.toPath()) from {{java.nio}}. I'm unsure if just the JavaDoc should be updated or the old behavior be restored: I noticed the bug because we catch a {{FileNotFoundException}}, which doesn't work for 2.12 and above. {code:title=Old Stacktrace} java.io.FileNotFoundException: doesnt-exist.txt (No such file or directory) at java.base/java.io.FileInputStream.open0(Native Method) ~[na:na] at java.base/java.io.FileInputStream.open(FileInputStream.java:219) ~[na:na] at java.base/java.io.FileInputStream.(FileInputStream.java:157) ~[na:na] at org.apache.commons.io.FileUtils.openInputStream(FileUtils.java:2388) ~[commons-io-2.11.0.jar:2.11.0] at org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:2506) ~[commons-io-2.11.0.jar:2.11.0] at