ARTEMIS-2320 Fix IntLongMath errorprone warning

Expression of type int may overflow before being assigned to a long
    (see https://errorprone.info/bugpattern/IntLongMath)
This commit is contained in:
Jiri Danek 2019-04-25 15:07:48 +02:00 committed by Michael Andre Pearce
parent fc51a5fcde
commit f7a36300ef
5 changed files with 11 additions and 11 deletions

View File

@ -387,7 +387,7 @@ public class ClientMessageImpl extends CoreMessage implements ClientMessageInter
if (isLargeMessage()) { if (isLargeMessage()) {
return getBodyBuffer().writerIndex(); return getBodyBuffer().writerIndex();
} else { } else {
return getBodyBuffer().writerIndex() - BODY_OFFSET; return (long) getBodyBuffer().writerIndex() - BODY_OFFSET;
} }
} }

View File

@ -110,7 +110,7 @@ final class MappedSequentialFile implements SequentialFile {
@Override @Override
public boolean fits(int size) { public boolean fits(int size) {
checkIsOpen(); checkIsOpen();
final long newPosition = this.mappedFile.position() + size; final long newPosition = (long) this.mappedFile.position() + size;
final boolean hasRemaining = newPosition <= this.mappedFile.length(); final boolean hasRemaining = newPosition <= this.mappedFile.length();
return hasRemaining; return hasRemaining;
} }

View File

@ -1398,9 +1398,9 @@ public class QueueImpl extends CriticalComponentImpl implements Queue {
if (pageSubscription != null) { if (pageSubscription != null) {
// messageReferences will have depaged messages which we need to discount from the counter as they are // messageReferences will have depaged messages which we need to discount from the counter as they are
// counted on the pageSubscription as well // counted on the pageSubscription as well
return pendingMetrics.getMessageCount() + getScheduledCount() + getDeliveringCount() + pageSubscription.getMessageCount(); return (long) pendingMetrics.getMessageCount() + getScheduledCount() + getDeliveringCount() + pageSubscription.getMessageCount();
} else { } else {
return pendingMetrics.getMessageCount() + getScheduledCount() + getDeliveringCount(); return (long) pendingMetrics.getMessageCount() + getScheduledCount() + getDeliveringCount();
} }
} }
@ -1419,9 +1419,9 @@ public class QueueImpl extends CriticalComponentImpl implements Queue {
public long getDurableMessageCount() { public long getDurableMessageCount() {
if (isDurable()) { if (isDurable()) {
if (pageSubscription != null) { if (pageSubscription != null) {
return pendingMetrics.getDurableMessageCount() + getDurableScheduledCount() + getDurableDeliveringCount() + pageSubscription.getMessageCount(); return (long) pendingMetrics.getDurableMessageCount() + getDurableScheduledCount() + getDurableDeliveringCount() + pageSubscription.getMessageCount();
} else { } else {
return pendingMetrics.getDurableMessageCount() + getDurableScheduledCount() + getDurableDeliveringCount(); return (long) pendingMetrics.getDurableMessageCount() + getDurableScheduledCount() + getDurableDeliveringCount();
} }
} }
return 0; return 0;

View File

@ -1334,7 +1334,7 @@ public abstract class ActiveMQTestBase extends Assert {
final ActiveMQServer backup) { final ActiveMQServer backup) {
ClientSessionFactoryInternal sessionFactory = (ClientSessionFactoryInternal) sessionFactoryP; ClientSessionFactoryInternal sessionFactory = (ClientSessionFactoryInternal) sessionFactoryP;
final ActiveMQServerImpl actualServer = (ActiveMQServerImpl) backup; final ActiveMQServerImpl actualServer = (ActiveMQServerImpl) backup;
final long toWait = seconds * 1000; final long toWait = seconds * 1000L;
final long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
int loop = 0; int loop = 0;
//Note: if maxLoop is too small there won't be //Note: if maxLoop is too small there won't be
@ -1382,7 +1382,7 @@ public abstract class ActiveMQTestBase extends Assert {
public static final void waitForRemoteBackup(ClientSessionFactory sessionFactory, int seconds) { public static final void waitForRemoteBackup(ClientSessionFactory sessionFactory, int seconds) {
ClientSessionFactoryInternal factoryInternal = (ClientSessionFactoryInternal) sessionFactory; ClientSessionFactoryInternal factoryInternal = (ClientSessionFactoryInternal) sessionFactory;
final long toWait = seconds * 1000; final long toWait = seconds * 1000L;
final long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
while (true) { while (true) {
if (factoryInternal.getBackupConnector() != null) { if (factoryInternal.getBackupConnector() != null) {
@ -1783,7 +1783,7 @@ public abstract class ActiveMQTestBase extends Assert {
journal.load(committedRecords, preparedTransactions, null, false); journal.load(committedRecords, preparedTransactions, null, false);
for (RecordInfo info : committedRecords) { for (RecordInfo info : committedRecords) {
Integer ikey = new Integer(info.getUserRecordType()); Integer ikey = (int) info.getUserRecordType();
AtomicInteger value = recordsType.get(ikey); AtomicInteger value = recordsType.get(ikey);
if (value == null) { if (value == null) {
value = new AtomicInteger(); value = new AtomicInteger();
@ -1812,7 +1812,7 @@ public abstract class ActiveMQTestBase extends Assert {
if (key == 0) { if (key == 0) {
System.out.println("huh?"); System.out.println("huh?");
} }
Integer ikey = new Integer(key); Integer ikey = (int) key;
AtomicInteger value = recordsType.get(ikey); AtomicInteger value = recordsType.get(ikey);
if (value == null) { if (value == null) {
value = new AtomicInteger(); value = new AtomicInteger();

View File

@ -67,7 +67,7 @@ public class PageCountSyncOnNonTXTest extends SpawnedTestBase {
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
timeToRun = 30000 + RandomUtil.randomPositiveInt() % 1000; timeToRun = 30000L + RandomUtil.randomPositiveInt() % 1000;
} }
@Test @Test