You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2016/12/21 15:59:59 UTC

[10/12] ant git commit: false positives and trivial fixes

false positives and trivial fixes


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/f74ca522
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/f74ca522
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/f74ca522

Branch: refs/heads/master
Commit: f74ca5229940d6b8aa532e560a9d4832c1a2d2d7
Parents: 6016294
Author: Stefan Bodewig <bo...@apache.org>
Authored: Wed Dec 21 16:57:10 2016 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Wed Dec 21 16:57:10 2016 +0100

----------------------------------------------------------------------
 .../org/apache/tools/ant/filters/SortFilter.java    |  2 +-
 .../org/apache/tools/ant/taskdefs/ExecuteJava.java  |  2 +-
 .../org/apache/tools/ant/taskdefs/Manifest.java     |  2 +-
 .../tools/ant/types/resources/ArchiveResource.java  |  2 +-
 .../tools/ant/types/resources/MappedResource.java   |  2 +-
 .../ant/types/resources/ResourceDecorator.java      | 16 +++++++++++++++-
 .../tools/ant/types/resources/StringResource.java   | 11 +++++++++++
 .../tools/ant/types/resources/URLResource.java      |  2 +-
 .../org/apache/tools/ant/util/ResourceUtils.java    |  4 ++--
 src/main/org/apache/tools/bzip2/BlockSort.java      |  2 +-
 src/main/org/apache/tools/tar/TarUtils.java         |  2 +-
 11 files changed, 36 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/f74ca522/src/main/org/apache/tools/ant/filters/SortFilter.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/filters/SortFilter.java b/src/main/org/apache/tools/ant/filters/SortFilter.java
index 471660c..44e8d72 100644
--- a/src/main/org/apache/tools/ant/filters/SortFilter.java
+++ b/src/main/org/apache/tools/ant/filters/SortFilter.java
@@ -362,7 +362,7 @@ public final class SortFilter extends BaseParamFilterReader
             if (reverse) {
                 Collections.sort(lines, new Comparator<String>() {
                         public int compare(String s1, String s2) {
-                            return (-s1.compareTo(s2));
+                            return (-s1.compareTo(s2)); //NOSONAR
                         }
                     });
             } else {

http://git-wip-us.apache.org/repos/asf/ant/blob/f74ca522/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java b/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java
index ef16c5c..b36f2fe 100644
--- a/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java
+++ b/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java
@@ -151,7 +151,7 @@ public class ExecuteJava implements Runnable, TimeoutObserver {
                     + " is not declared static");
             }
             if (timeout == null) {
-                run();
+                run(); //NOSONAR
             } else {
                 thread = new Thread(this, "ExecuteJava");
                 Task currentThreadTask

http://git-wip-us.apache.org/repos/asf/ant/blob/f74ca522/src/main/org/apache/tools/ant/taskdefs/Manifest.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/Manifest.java b/src/main/org/apache/tools/ant/taskdefs/Manifest.java
index 06c74dd..0d7c05e 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Manifest.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Manifest.java
@@ -1066,7 +1066,7 @@ public class Manifest {
         try {
             write(new PrintWriter(sw));
         } catch (IOException e) {
-            return null;
+            return "";
         }
         return sw.toString();
     }

http://git-wip-us.apache.org/repos/asf/ant/blob/f74ca522/src/main/org/apache/tools/ant/types/resources/ArchiveResource.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/ArchiveResource.java b/src/main/org/apache/tools/ant/types/resources/ArchiveResource.java
index 308de03..09ce032 100644
--- a/src/main/org/apache/tools/ant/types/resources/ArchiveResource.java
+++ b/src/main/org/apache/tools/ant/types/resources/ArchiveResource.java
@@ -216,7 +216,7 @@ public abstract class ArchiveResource extends Resource {
         if (isReference()) {
             return getCheckedRef().equals(another);
         }
-        if (another == null || !(another.getClass().equals(getClass()))) {
+        if (another == null || another.getClass() != getClass()) {
             return false;
         }
         ArchiveResource r = (ArchiveResource) another;

http://git-wip-us.apache.org/repos/asf/ant/blob/f74ca522/src/main/org/apache/tools/ant/types/resources/MappedResource.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/MappedResource.java b/src/main/org/apache/tools/ant/types/resources/MappedResource.java
index 339c88b..c18cbf4 100644
--- a/src/main/org/apache/tools/ant/types/resources/MappedResource.java
+++ b/src/main/org/apache/tools/ant/types/resources/MappedResource.java
@@ -95,7 +95,7 @@ public class MappedResource extends ResourceDecorator {
      */
     @Override
     public boolean equals(Object other) {
-        if (other == null || !other.getClass().equals(getClass())) {
+        if (other == null || other.getClass() != getClass()) {
             return false;
         }
         MappedResource m = (MappedResource) other;

http://git-wip-us.apache.org/repos/asf/ant/blob/f74ca522/src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java b/src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java
index 3806cf2..9eb8c1d 100644
--- a/src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java
+++ b/src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java
@@ -74,6 +74,7 @@ public abstract class ResourceDecorator extends Resource {
      * Get the name of the resource.
      * @return the name of the wrapped resource.
      */
+    @Override
     public String getName() {
         return getResource().getName();
     }
@@ -82,6 +83,7 @@ public abstract class ResourceDecorator extends Resource {
      * The exists attribute tells whether a file exists.
      * @return true if this resource exists.
      */
+    @Override
     public boolean isExists() {
         return getResource().isExists();
     }
@@ -92,6 +94,7 @@ public abstract class ResourceDecorator extends Resource {
      * @return 0 if the resource does not exist to mirror the behavior
      * of {@link java.io.File File}.
      */
+    @Override
     public long getLastModified() {
         return getResource().getLastModified();
     }
@@ -100,6 +103,7 @@ public abstract class ResourceDecorator extends Resource {
      * Tells if the resource is a directory.
      * @return boolean flag indicating if the resource is a directory.
      */
+    @Override
     public boolean isDirectory() {
         return getResource().isDirectory();
     }
@@ -109,6 +113,7 @@ public abstract class ResourceDecorator extends Resource {
      * @return the size, as a long, 0 if the Resource does not exist (for
      *         compatibility with java.io.File), or UNKNOWN_SIZE if not known.
      */
+    @Override
     public long getSize() {
         return getResource().getSize();
     }
@@ -121,6 +126,7 @@ public abstract class ResourceDecorator extends Resource {
      * @throws UnsupportedOperationException if InputStreams are not
      *         supported for this Resource type.
      */
+    @Override
     public InputStream getInputStream() throws IOException {
         return getResource().getInputStream();
     }
@@ -133,6 +139,7 @@ public abstract class ResourceDecorator extends Resource {
      * @throws UnsupportedOperationException if OutputStreams are not
      *         supported for this Resource type.
      */
+    @Override
     public OutputStream getOutputStream() throws IOException {
         return getResource().getOutputStream();
     }
@@ -141,6 +148,7 @@ public abstract class ResourceDecorator extends Resource {
      * Fulfill the ResourceCollection contract.
      * @return whether this Resource is a FileProvider.
      */
+    @Override
     public boolean isFilesystemOnly() {
         return as(FileProvider.class) != null;
     }
@@ -149,6 +157,7 @@ public abstract class ResourceDecorator extends Resource {
      * Overrides the base version.
      * @param r the Reference to set.
      */
+    @Override
     public void setRefid(Reference r) {
         if (resource != null) {
             throw noChildrenAllowed();
@@ -159,6 +168,7 @@ public abstract class ResourceDecorator extends Resource {
     /**
      * {@inheritDoc}
      */
+    @Override
     public <T> T as(Class<T> clazz) {
         return getResource().as(clazz);
     }
@@ -166,6 +176,7 @@ public abstract class ResourceDecorator extends Resource {
     /**
      * {@inheritDoc}
      */
+    @Override
     public int compareTo(Resource other) {
         if (other == this) {
             return 0;
@@ -181,7 +192,9 @@ public abstract class ResourceDecorator extends Resource {
      * Get the hash code for this Resource.
      * @return hash code as int.
      */
-    public int hashCode() {
+    @Override
+    public int hashCode() { // NOSONAR
+        // super.equals + compareTo are consistent with this implementation
         return (getClass().hashCode() << 4) | getResource().hashCode();
     }
 
@@ -267,4 +280,5 @@ public abstract class ResourceDecorator extends Resource {
         throw new BuildException("you can't change the size of a "
                                  + getDataTypeName());
     }
+
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/f74ca522/src/main/org/apache/tools/ant/types/resources/StringResource.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/StringResource.java b/src/main/org/apache/tools/ant/types/resources/StringResource.java
index b12a2e1..fe7b295 100644
--- a/src/main/org/apache/tools/ant/types/resources/StringResource.java
+++ b/src/main/org/apache/tools/ant/types/resources/StringResource.java
@@ -71,6 +71,7 @@ public class StringResource extends Resource {
      * Enforce String immutability.
      * @param s the new name/value for this StringResource.
      */
+    @Override
     public synchronized void setName(String s) {
         if (getName() != null) {
             throw new BuildException(new ImmutableResourceException());
@@ -90,6 +91,7 @@ public class StringResource extends Resource {
      * Synchronize access.
      * @return the name/value of this StringResource.
      */
+    @Override
     public synchronized String getName() {
         return super.getName();
     }
@@ -107,6 +109,7 @@ public class StringResource extends Resource {
      *
      * @return true if this resource exists.
      */
+    @Override
     public boolean isExists() {
         return getValue() != null;
     }
@@ -144,6 +147,7 @@ public class StringResource extends Resource {
      * @return the size, as a long, 0 if the Resource does not exist (for
      *         compatibility with java.io.File), or UNKNOWN_SIZE if not known.
      */
+    @Override
     public synchronized long getSize() {
         return isReference() ? ((Resource) getCheckedRef()).getSize()
                 : getContent().length();
@@ -153,7 +157,9 @@ public class StringResource extends Resource {
      * Get the hash code for this Resource.
      * @return hash code as int.
      */
+    @Override
     public synchronized int hashCode() {
+        // super.equals + super.compareTo are consistent with this implementation
         if (isReference()) {
             return getCheckedRef().hashCode();
         }
@@ -166,6 +172,7 @@ public class StringResource extends Resource {
      * @return the string contents of the resource.
      * @since Ant 1.7
      */
+    @Override
     public String toString() {
         return String.valueOf(getContent());
     }
@@ -178,6 +185,7 @@ public class StringResource extends Resource {
      * @throws UnsupportedOperationException if InputStreams are not
      *         supported for this Resource type.
      */
+    @Override
     public synchronized InputStream getInputStream() throws IOException {
         if (isReference()) {
             return ((Resource) getCheckedRef()).getInputStream();
@@ -198,6 +206,7 @@ public class StringResource extends Resource {
      * @throws UnsupportedOperationException if OutputStreams are not
      *         supported for this Resource type.
      */
+    @Override
     public synchronized OutputStream getOutputStream() throws IOException {
         if (isReference()) {
             return ((Resource) getCheckedRef()).getOutputStream();
@@ -212,6 +221,7 @@ public class StringResource extends Resource {
      * Overrides the super version.
      * @param r the Reference to set.
      */
+    @Override
     public void setRefid(Reference r) {
         if (encoding != DEFAULT_ENCODING) {
             throw tooManyAttributes();
@@ -250,6 +260,7 @@ public class StringResource extends Resource {
             baos = (ByteArrayOutputStream) out;
         }
 
+        @Override
         public void close() throws IOException {
             super.close();
             String result = encoding == null

http://git-wip-us.apache.org/repos/asf/ant/blob/f74ca522/src/main/org/apache/tools/ant/types/resources/URLResource.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/URLResource.java b/src/main/org/apache/tools/ant/types/resources/URLResource.java
index 70d6c9b..027a9bd 100644
--- a/src/main/org/apache/tools/ant/types/resources/URLResource.java
+++ b/src/main/org/apache/tools/ant/types/resources/URLResource.java
@@ -313,7 +313,7 @@ public class URLResource extends Resource implements URLProvider {
         if (isReference()) {
             return getCheckedRef().equals(another);
         }
-        if (another == null || !(another.getClass().equals(getClass()))) {
+        if (another == null || another.getClass() != getClass()) {
             return false;
         }
         URLResource otheru = (URLResource) another;

http://git-wip-us.apache.org/repos/asf/ant/blob/f74ca522/src/main/org/apache/tools/ant/util/ResourceUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/ResourceUtils.java b/src/main/org/apache/tools/ant/util/ResourceUtils.java
index 6397f71..518ed5a 100644
--- a/src/main/org/apache/tools/ant/util/ResourceUtils.java
+++ b/src/main/org/apache/tools/ant/util/ResourceUtils.java
@@ -72,7 +72,7 @@ public class ResourceUtils {
      */
     public static final String ISO_8859_1 = "ISO-8859-1";
 
-    private static final long MAX_IO_CHUNK_SIZE = 16*1024*1024; // 16 MB
+    private static final long MAX_IO_CHUNK_SIZE = 16*1024*1024l; // 16 MB
 
     /**
      * Tells which source files should be reprocessed based on the
@@ -630,7 +630,7 @@ public class ResourceUtils {
                 }
                 expected = in1.readLine();
             }
-            return in2.readLine() == null ? 0 : -1;
+            return in2.readLine() == null ? 0 : -1; //NOSONAR
         } finally {
             FileUtils.close(in1);
             FileUtils.close(in2);

http://git-wip-us.apache.org/repos/asf/ant/blob/f74ca522/src/main/org/apache/tools/bzip2/BlockSort.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/bzip2/BlockSort.java b/src/main/org/apache/tools/bzip2/BlockSort.java
index b382470..073b223 100644
--- a/src/main/org/apache/tools/bzip2/BlockSort.java
+++ b/src/main/org/apache/tools/bzip2/BlockSort.java
@@ -975,7 +975,7 @@ class BlockSort {
             runningOrder[i] = i;
         }
 
-        for (int h = 364; h != 1;) {
+        for (int h = 364; h != 1;) { //NOSONAR
             h /= 3;
             for (int i = h; i <= 255; i++) {
                 final int vv = runningOrder[i];

http://git-wip-us.apache.org/repos/asf/ant/blob/f74ca522/src/main/org/apache/tools/tar/TarUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/tar/TarUtils.java b/src/main/org/apache/tools/tar/TarUtils.java
index 12bd1da..f86154e 100644
--- a/src/main/org/apache/tools/tar/TarUtils.java
+++ b/src/main/org/apache/tools/tar/TarUtils.java
@@ -191,7 +191,7 @@ public class TarUtils {
         if (negative) {
             // 2's complement
             val--;
-            val ^= (long) Math.pow(2, (length - 1) * 8) - 1;
+            val ^= (long) Math.pow(2, (length - 1) * 8.0) - 1;
         }
         return negative ? -val : val;
     }