walkmod / walkmod-pmd-plugin

Walkmod plugin to fix the code according the PMD rules
2 stars 2 forks source link

variable declaration lost on merging ifs #6

Closed cal101 closed 7 years ago

cal101 commented 7 years ago
     protected static void safeMove(final VFile sourceFile, final VFile targetFile, boolean deleteBeforeMove) {
-        if (deleteBeforeMove && targetFile.exists()) {
-            if (!targetFile.delete()) {
-                boolean exists = targetFile.exists();
-                throw new UncheckedApplicationException("file: " + targetFile + " cant be deleted"
-                            + " (file " + (exists ? "exists)" : "does not exist)")
-
-                );
-            }
+        if ((deleteBeforeMove && targetFile.exists()) && !targetFile.delete()) {
+            throw new UncheckedApplicationException("file: " + targetFile + " cant be deleted" + " (file " + (exists ? "exists)" : "does not exist)"));
         }
rpau commented 7 years ago

It happens due to an invalid order of visitors' execution. It is the same than issue #9.