Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileUtils can never throw an IOException #180

Open
bmarwell opened this issue Jan 20, 2022 · 5 comments
Open

FileUtils can never throw an IOException #180

bmarwell opened this issue Jan 20, 2022 · 5 comments

Comments

@bmarwell
Copy link

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:

/**
* Return a list of files as String depending options.
*
* @param directory the directory to scan
* @param includes the includes pattern, comma separated
* @param excludes the excludes pattern, comma separated
* @param includeBasedir true to include the base dir in each String of file
* @param isCaseSensitive true if case sensitive
* @param getFiles true if get files
* @param getDirectories true if get directories
* @return a list of files as String
* @throws IOException io issue
*/
public static List<String> getFileAndDirectoryNames( File directory, String includes, String excludes,
boolean includeBasedir, boolean isCaseSensitive,
boolean getFiles, boolean getDirectories )
throws IOException
{
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir( directory );
if ( includes != null )
{
scanner.setIncludes( StringUtils.split( includes, "," ) );
}
if ( excludes != null )
{
scanner.setExcludes( StringUtils.split( excludes, "," ) );
}
scanner.setCaseSensitive( isCaseSensitive );
scanner.scan();
List<String> list = new ArrayList<String>();
if ( getFiles )
{
String[] files = scanner.getIncludedFiles();
for ( String file : files )
{
if ( includeBasedir )
{
list.add( directory + FileUtils.FS + file );
}
else
{
list.add( file );
}
}
}
if ( getDirectories )
{
String[] directories = scanner.getIncludedDirectories();
for ( String directory1 : directories )
{
if ( includeBasedir )
{
list.add( directory + FileUtils.FS + directory1 );
}
else
{
list.add( directory1 );
}
}
}
return list;
}

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.

@slachiewicz
Copy link
Member

all inside FileUtils needs cleanup and move directly to NIO

@michael-o
Copy link
Member

all inside FileUtils needs cleanup and move directly to NIO

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

@bmarwell
Copy link
Author

Yes, it is just Files.walk essentially.

@elharo
Copy link

elharo commented Apr 6, 2023

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.

@michael-o
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants