plexus-utils icon indicating copy to clipboard operation
plexus-utils copied to clipboard

FileUtils can never throw an IOException

Open bmarwell opened this issue 4 years ago • 5 comments

Hi,

I did a quick check of FileUtils::getFileAndDirectoryNames

Signature:

public static List<String> getFileAndDirectoryNames( File directory, String includes, String excludes,
                                                         boolean includeBasedir, boolean isCaseSensitive,
                                                         boolean getFiles, boolean getDirectories )
        throws IOException;

Source: https://github.com/codehaus-plexus/plexus-utils/blob/1f93cc8583f872b7bc01bef1dc32979f0a2335bb/src/main/java/org/codehaus/plexus/util/FileUtils.java#L1833-L1906

It seems it can never throw an IOException. If we removed it, a lot of Maven Mojos could be made MUCH simpler.

One of the reasons is that canGenerateReport is called both in execute and executeReport. One throws a MojoExecutionException, the other one a MavenReportException, but canGenerateReport can throw neither. This means, that it is impossible to deal with IOExceptions in Maven Reports anyway.

bmarwell avatar Jan 20 '22 07:01 bmarwell

all inside FileUtils needs cleanup and move directly to NIO

slachiewicz avatar Apr 23 '22 18:04 slachiewicz

all inside FileUtils needs cleanup and move directly to NIO

If the wrapper is thin, then I would even prefer to throw it away.

michael-o avatar Apr 23 '22 18:04 michael-o

Yes, it is just Files.walk essentially.

bmarwell avatar Apr 23 '22 20:04 bmarwell

Yes, please deprecate all of this. It's a remnant of a time when the Java class library was much less powerful than it has been for the last ten years. If we were starting over, this wouldn't be needed.

elharo avatar Apr 06 '23 12:04 elharo

https://issues.apache.org/jira/browse/MSHARED-1032

michael-o avatar Apr 06 '23 12:04 michael-o

so with MSHARED-1032 implemented - this issue is no longer valid?

slachiewicz avatar Dec 15 '24 22:12 slachiewicz