activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [3/4] activemq-artemis git commit: ARTEMIS-1135: Prevent overflow in `DayCounter`
Date Tue, 02 May 2017 17:00:58 GMT
ARTEMIS-1135: Prevent overflow in `DayCounter`

Use `long` array for hourly counters instead of `int` array.
Prevents overflow when the number of new messages (a `long`) is added.
Fixes one of the "Implicit narrowing conversion in compound assignment"
alerts on https://lgtm.com/projects/g/apache/activemq-artemis/alerts.


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/52a5b855
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/52a5b855
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/52a5b855

Branch: refs/heads/master
Commit: 52a5b85557e7bb069a1ae3d56669a11f3620b31a
Parents: b998a8b
Author: Aditya Sharad <aditya@semmle.com>
Authored: Sat Apr 29 15:52:08 2017 +0100
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Tue May 2 13:00:46 2017 -0400

----------------------------------------------------------------------
 .../artemis/api/core/management/DayCounterInfo.java     | 10 +++++-----
 .../artemis/core/messagecounter/MessageCounter.java     | 12 ++++++------
 .../core/messagecounter/impl/MessageCounterHelper.java  |  2 +-
 3 files changed, 12 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/52a5b855/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/DayCounterInfo.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/DayCounterInfo.java
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/DayCounterInfo.java
index 4cb124b..1dce276 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/DayCounterInfo.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/DayCounterInfo.java
@@ -32,7 +32,7 @@ public final class DayCounterInfo {
 
    private final String date;
 
-   private final int[] counters;
+   private final long[] counters;
 
    // Static --------------------------------------------------------
 
@@ -41,7 +41,7 @@ public final class DayCounterInfo {
       JsonArrayBuilder counters = JsonLoader.createArrayBuilder();
       for (DayCounterInfo info : infos) {
          JsonArrayBuilder counter = JsonLoader.createArrayBuilder();
-         for (int c : info.getCounters()) {
+         for (long c : info.getCounters()) {
             counter.add(c);
          }
          JsonObjectBuilder dci = JsonLoader.createObjectBuilder().add("date", info.getDate()).add("counters",
counter);
@@ -63,7 +63,7 @@ public final class DayCounterInfo {
 
          JsonObject counter = (JsonObject) dayCounters.get(i);
          JsonArray hour = counter.getJsonArray("counters");
-         int[] hourCounters = new int[24];
+         long[] hourCounters = new long[24];
          for (int j = 0; j < 24; j++) {
             hourCounters[j] = hour.getInt(j);
          }
@@ -75,7 +75,7 @@ public final class DayCounterInfo {
 
    // Constructors --------------------------------------------------
 
-   public DayCounterInfo(final String date, final int[] counters) {
+   public DayCounterInfo(final String date, final long[] counters) {
       this.date = date;
       this.counters = counters;
    }
@@ -93,7 +93,7 @@ public final class DayCounterInfo {
     * Returns a 24-length array corresponding to the number of messages added to the queue
     * for the given hour of the day.
     */
-   public int[] getCounters() {
+   public long[] getCounters() {
       return counters;
    }
 }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/52a5b855/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/MessageCounter.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/MessageCounter.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/MessageCounter.java
index 522445d..3ee5e4a 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/MessageCounter.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/MessageCounter.java
@@ -395,7 +395,7 @@ public class MessageCounter {
 
       GregorianCalendar date = null;
 
-      int[] counters = new int[DayCounter.HOURS];
+      long[] counters = new long[DayCounter.HOURS];
 
       /**
        * Constructor
@@ -415,17 +415,17 @@ public class MessageCounter {
          for (int i = 0; i < DayCounter.HOURS; i++) {
             if (i < hour) {
                if (isStartDay) {
-                  counters[i] = -1;
+                  counters[i] = -1L;
                } else {
-                  counters[i] = 0;
+                  counters[i] = 0L;
                }
             } else {
-               counters[i] = -1;
+               counters[i] = -1L;
             }
          }
 
          // set the array element of the current hour to '0'
-         counters[hour] = 0;
+         counters[hour] = 0L;
       }
 
       /**
@@ -437,7 +437,7 @@ public class MessageCounter {
          return (GregorianCalendar) date.clone();
       }
 
-      public int[] getCounters() {
+      public long[] getCounters() {
          return counters;
       }
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/52a5b855/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/impl/MessageCounterHelper.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/impl/MessageCounterHelper.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/impl/MessageCounterHelper.java
index 1688985..c8fe282 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/impl/MessageCounterHelper.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/impl/MessageCounterHelper.java
@@ -38,7 +38,7 @@ public class MessageCounterHelper {
       DayCounterInfo[] infos = new DayCounterInfo[history.size()];
       for (int i = 0; i < infos.length; i++) {
          DayCounter dayCounter = history.get(i);
-         int[] counters = dayCounter.getCounters();
+         long[] counters = dayCounter.getCounters();
          GregorianCalendar date = dayCounter.getDate();
 
          DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);


Mime
View raw message