Skip to content

Commit

Permalink
Merge pull request eclipse-aspectj#100 from turbanoff/File.exists_bef…
Browse files Browse the repository at this point in the history
…ore_File.isDirectory_is_redundant

Remove redundant File.exists() check before File.isDirectory()
  • Loading branch information
aclement authored Nov 29, 2021
2 parents 90cfa08 + 793a015 commit 27aba3f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ public ClassPath(String class_path) {
File file = new File(path);

try {
if (file.exists()) {
if (file.isDirectory()) {
vec.add(new Dir(path));
} else if (file.getName().endsWith("jrt-fs.jar")) { // TODO a bit crude...
if (file.isDirectory()) {
vec.add(new Dir(path));
} else if (file.exists()) {
if (file.getName().endsWith("jrt-fs.jar")) { // TODO a bit crude...
vec.add(new JImage());
} else {
vec.add(new Zip(new ZipFile(file)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void checkLicense(String module) {

void checkSourceDirectory(File srcDir, String module) {
final String label = "source dir " + srcDir + " (module " + module + ")";
assertTrue(label, (srcDir.exists() && srcDir.isDirectory()));
assertTrue(label, srcDir.isDirectory());
String license = getLicense(module);
// if (replacing) {
// if (replacing && true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ private boolean changedAndNeedsFullBuild(List oldPath, List newPath, boolean che
if (f.exists() && !f.isDirectory() && (f.lastModified() >= lastSuccessfulBuildTime)) {
return true;
}
if (checkClassFiles && f.exists() && f.isDirectory()) {
if (checkClassFiles && f.isDirectory()) {

// We should use here a list/set of directories we know have or have not changed - some kind of
// List<File> buildConfig.getClasspathEntriesWithChangedContents()
Expand Down Expand Up @@ -1045,7 +1045,7 @@ private boolean classpathChangedAndNeedsFullBuild(List<String> oldPath, List<Str
if (f.exists() && !f.isDirectory() && (f.lastModified() >= lastSuccessfulBuildTime)) {
return true;
}
if (checkClassFiles && f.exists() && f.isDirectory()) {
if (checkClassFiles && f.isDirectory()) {

// We should use here a list/set of directories we know have or have not changed - some kind of
// List<File> buildConfig.getClasspathEntriesWithChangedContents()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ private void expandArgfile(File argfile, List includes, List arguments) {
File parent = argfile.getParentFile();

// Sanity check
if (parent == null || !parent.exists() || !parent.isDirectory()) {
if (parent == null || !parent.isDirectory()) {
return;
}

Expand Down
5 changes: 2 additions & 3 deletions testing/src/test/java/org/aspectj/testing/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public static void descendFileTree(File file, FileFilter filter) {
* return true;
* }}, true);</code></pre>
* @param file root/starting point. If a file, the only one visited.
* @param filter supplies boolean accept(File) method
* @param fileFilter supplies boolean accept(File) method
* @param userRecursion - if true, do accept() on dirs; else, recurse
* @return false if any fileFilter.accept(File) did.
* @throws IllegalArgumentException if file or fileFilter is null
Expand Down Expand Up @@ -655,7 +655,6 @@ public static boolean copy(InputStream src, OutputStream dest,
*/
protected static boolean deleteDirectory(File dir) {
return ((null != dir)
&& dir.exists()
&& dir.isDirectory()
&& FileUtil.descendFileTree(dir, DELETE_FILES, false)
&& FileUtil.descendFileTree(dir, DELETE_DIRS, true)
Expand All @@ -675,7 +674,7 @@ public static String[] getPaths(File[] files) { // util
protected static final FileFilter DELETE_DIRS = new FileFilter() {
public boolean accept(File file) {
return ((null != file) && file.isDirectory()
&& file.exists() && file.delete());
&& file.delete());
}
};
protected static final FileFilter DELETE_FILES = new FileFilter() {
Expand Down

0 comments on commit 27aba3f

Please sign in to comment.