[
https://issues.apache.org/jira/browse/IO-711?focusedWorklogId=543855&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-543855
]
ASF GitHub Bot logged work on IO-711:
-------------------------------------
Author: ASF GitHub Bot
Created on: 28/Jan/21 20:12
Start Date: 28/Jan/21 20:12
Worklog Time Spent: 10m
Work Description: garydgregory commented on a change in pull request #196:
URL: https://github.com/apache/commons-io/pull/196#discussion_r566371592
##########
File path: src/main/java/org/apache/commons/io/FileDeleteStrategy.java
##########
@@ -144,6 +147,7 @@ public boolean deleteQuietly(final File fileToDelete) {
* @throws IOException if an error occurs during file deletion
*/
protected boolean doDelete(final File file) throws IOException {
+ Objects.requireNonNull(file,"file");
Review comment:
Fix formatting.
##########
File path: src/main/java/org/apache/commons/io/FileSystemUtils.java
##########
@@ -271,9 +272,8 @@ public static long freeSpaceKb(final long timeout) throws
IOException {
* @throws IOException if an error occurs when finding the free space
*/
long freeSpaceOS(final String path, final int os, final boolean kb, final
long timeout) throws IOException {
- if (path == null) {
- throw new IllegalArgumentException("Path must not be null");
- }
+ Objects.requireNonNull(path,"path");
Review comment:
Fix formatting.
##########
File path: src/main/java/org/apache/commons/io/FileSystemUtils.java
##########
@@ -396,6 +396,7 @@ long parseDir(final String line, final String path) throws
IOException {
*/
long freeSpaceUnix(final String path, final boolean kb, final boolean
posix, final long timeout)
throws IOException {
+ Objects.requireNonNull(path,"path");
Review comment:
Fix formatting.
##########
File path: src/main/java/org/apache/commons/io/FileUtils.java
##########
@@ -340,6 +341,7 @@ public static void cleanDirectory(final File directory)
throws IOException {
* @see #forceDeleteOnExit(File)
*/
private static void cleanDirectoryOnExit(final File directory) throws
IOException {
+ Objects.requireNonNull(directory, "directory");
Review comment:
-1: no need, already done on the next line in `listFiles`.
##########
File path: src/main/java/org/apache/commons/io/FilenameUtils.java
##########
@@ -1510,6 +1510,9 @@ public static boolean wildcardMatch(final String
fileName, final String wildcard
* @return true if the given name is a valid host name
*/
private static boolean isValidHostName(final String name) {
+ if(Objects.isNull(name)) {
Review comment:
Fix formatting and no need to call an API meant for use in lambdas when
`name == null` would do.
##########
File path:
src/main/java/org/apache/commons/io/monitor/FileAlterationObserver.java
##########
@@ -200,12 +201,9 @@ public FileAlterationObserver(final File directory, final
FileFilter fileFilter,
*/
protected FileAlterationObserver(final FileEntry rootEntry, final
FileFilter fileFilter,
final IOCase caseSensitivity) {
- if (rootEntry == null) {
- throw new IllegalArgumentException("Root entry is missing");
- }
- if (rootEntry.getFile() == null) {
- throw new IllegalArgumentException("Root directory is missing");
- }
+ Objects.requireNonNull(rootEntry, "rootEntry");
+ Objects.requireNonNull(rootEntry.getFile(),"rootDirectory");
Review comment:
Fix formatting.
##########
File path: src/main/java/org/apache/commons/io/FileUtils.java
##########
@@ -866,6 +868,8 @@ public static void copyFile(final File srcFile, final File
destFile, final CopyO
* @since 2.1
*/
public static long copyFile(final File input, final OutputStream output)
throws IOException {
+ Objects.requireNonNull(input, "input");
+ Objects.requireNonNull(output, "output");
Review comment:
-1: no need to check on `output`, this already done in `copyLarge`.
I'll stop this type of comment since these checks over the top in this PR.
IOW, let's not check for NPEs when we do not need to.
##########
File path: src/main/java/org/apache/commons/io/FileUtils.java
##########
@@ -314,6 +314,7 @@ public static long checksumCRC32(final File file) throws
IOException {
* @see #forceDelete(File)
*/
public static void cleanDirectory(final File directory) throws IOException
{
+ Objects.requireNonNull(directory, "directory");
Review comment:
-1: no need, already done on the next line in `listFiles`.
##########
File path: src/main/java/org/apache/commons/io/FileUtils.java
##########
@@ -1200,6 +1210,7 @@ public static void deleteDirectory(final File directory)
throws IOException {
* @throws IOException in case deletion is unsuccessful
*/
private static void deleteDirectoryOnExit(final File directory) throws
IOException {
+ Objects.requireNonNull(directory,"directory");
Review comment:
Fix formatting.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 543855)
Time Spent: 0.5h (was: 20m)
> Use Objects.requireNotNull for fail fast method/constructors
> ------------------------------------------------------------
>
> Key: IO-711
> URL: https://issues.apache.org/jira/browse/IO-711
> Project: Commons IO
> Issue Type: Improvement
> Components: Filters, Streams/Writers, Utilities
> Affects Versions: 2.8.0
> Reporter: Boris Unckel
> Priority: Major
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> Currently some NullPointer checks are IllegalArgumentException, at other
> points a lot of constructor and/or method logic happens before a null pointer
> occurs.
> The approach is to make these places use
> Objects.requireNonNull(sampleObject,"sampleObject");
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)