Use final.
Simpler boolean tests.
Fix test.
MODIFY
src/main/java/org/apache/commons/io/FileCleaningTracker.java
src/main/java/org/apache/commons/io/FileCleaningTracker.java
@@ -215,7 +215,7 @@ public synchronized void exitWhenFinished() {
@Override
public void run() {
// thread exits when exitWhenFinished is true and there are no more tracked objects
- while (exitWhenFinished == false || !trackers.isEmpty()) {
+ while (!exitWhenFinished || !trackers.isEmpty()) {
try {
// Wait for a tracker to remove.
final Tracker tracker = (Tracker) q.remove(); // cannot return null

MODIFY
src/main/java/org/apache/commons/io/FileDeleteStrategy.java
src/main/java/org/apache/commons/io/FileDeleteStrategy.java
@@ -98,7 +98,7 @@ protected FileDeleteStrategy(final String name) {
* @throws IOException if an error occurs during file deletion
*/
public void delete(final File fileToDelete) throws IOException {
- if (fileToDelete.exists() && doDelete(fileToDelete) == false) {
+ if (fileToDelete.exists() && !doDelete(fileToDelete)) {
throw new IOException("Deletion failed: " + fileToDelete);
}
}
@@ -115,7 +115,7 @@ public void delete(final File fileToDelete) throws IOException {
* @return true if the file was deleted, or there was no such file
*/
public boolean deleteQuietly(final File fileToDelete) {
- if (fileToDelete == null || fileToDelete.exists() == false) {
+ if (fileToDelete == null || !fileToDelete.exists()) {
return true;
}
try {

MODIFY
src/main/java/org/apache/commons/io/monitor/FileAlterationMonitor.java
src/main/java/org/apache/commons/io/monitor/FileAlterationMonitor.java
@@ -183,7 +183,7 @@ public synchronized void stop() throws Exception {
* @since 2.1
*/
public synchronized void stop(final long stopInterval) throws Exception {
- if (running == false) {
+ if (!running) {
throw new IllegalStateException("Monitor is not running");
}
running = false;

MODIFY
src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
@@ -241,7 +241,7 @@ private static Writer initWriter(final File file, final Object encoding, final b
} catch (final IOException e) {
ex.addSuppressed(e);
}
- if (fileExistedAlready == false) {
+ if (!fileExistedAlready) {
FileUtils.deleteQuietly(file);
}
throw ex;

MODIFY
src/main/java/org/apache/commons/io/output/LockableFileWriter.java
src/main/java/org/apache/commons/io/output/LockableFileWriter.java
@@ -270,7 +270,7 @@ private Writer initWriter(final File file, final Charset charset, final boolean
} catch (final IOException | RuntimeException ex) {
FileUtils.deleteQuietly(lockFile);
- if (fileExistedAlready == false) {
+ if (!fileExistedAlready) {
FileUtils.deleteQuietly(file);
}
throw ex;

MODIFY
src/test/java/org/apache/commons/io/monitor/FileAlterationMonitorTestCase.java
src/test/java/org/apache/commons/io/monitor/FileAlterationMonitorTestCase.java
@@ -56,23 +56,24 @@ public void testDefaultConstructor() {
@Test
public void testCollectionConstructorShouldDoNothingWithNullCollection() {
- Collection<FileAlterationObserver> observers = null;
+ final Collection<FileAlterationObserver> observers = null;
final FileAlterationMonitor monitor = new FileAlterationMonitor(0, observers);
assertFalse(monitor.getObservers().iterator().hasNext());
}
@Test
public void testCollectionConstructorShouldDoNothingWithNullObservers() {
- Collection<FileAlterationObserver> observers = new ArrayList<>(5);
+ final Collection<FileAlterationObserver> observers = new ArrayList<>(5);
final FileAlterationMonitor monitor = new FileAlterationMonitor(0, observers);
assertFalse(monitor.getObservers().iterator().hasNext());
}
@Test
public void testCollectionConstructor() {
- Collection<FileAlterationObserver> observers = Arrays.asList(new FileAlterationObserver("foo"));
- FileAlterationMonitor monitor = new FileAlterationMonitor(0, observers);
- Iterator<FileAlterationObserver> iterator = monitor.getObservers().iterator();
+ observer = new FileAlterationObserver("foo");
+ final Collection<FileAlterationObserver> observers = Arrays.asList(observer);
+ final FileAlterationMonitor monitor = new FileAlterationMonitor(0, observers);
+ final Iterator<FileAlterationObserver> iterator = monitor.getObservers().iterator();
assertEquals(observer, iterator.next());
}

- Use final.
- Simpler boolean tests.
- Fix test.