Hi Ken, Jan, Marina, Hong, Shalini, Jagadish, Lloyd,
In April I found and fixed an issue in JTA where the multiplication of
two integers and a subsequent cast to a long led to
IllegalArgumentException because the value had become negative.
https://glassfish.dev.java.net/issues/show_bug.cgi?id=7979
For example:
timer.schedule(this,timeout * 1000);
schedule() takes a long, but if 'timeout' is bigger than MAX_INT/1000,
the value will become negative.
Searching through the V3 source code I found 40 more cases in your
components: ejb, web, jta/jta, deploy, connection pool, jms, jmx.
Some of the 'timeout' variables might never reach a big value, or code
might not be used any more in V3, but as it's better safe than sorry
I've addressed them in the attached patch (added 'L' to integer 1000).
May I commit it to V3?
I found these by grepping "1000;" and "1000);", so I might have missed some.
Thanks,
Dies
Index: deployment/autodeploy/src/main/java/org/glassfish/deployment/autodeploy/AutodeployRetryManager.java
===================================================================
--- deployment/autodeploy/src/main/java/org/glassfish/deployment/autodeploy/AutodeployRetryManager.java (revision 31858)
+++ deployment/autodeploy/src/main/java/org/glassfish/deployment/autodeploy/AutodeployRetryManager.java (working copy)
@@ -401,7 +401,7 @@
* Delays the time when retries for this file will expire.
*/
protected void postponeRetryExpiration() {
- retryExpiration = System.currentTimeMillis() + timeout * 1000;
+ retryExpiration = System.currentTimeMillis() + timeout * 1000L;
}
}
Index: deployment/autodeploy/src/main/java/org/glassfish/deployment/autodeploy/AutoDeployService.java
===================================================================
--- deployment/autodeploy/src/main/java/org/glassfish/deployment/autodeploy/AutoDeployService.java (revision 31858)
+++ deployment/autodeploy/src/main/java/org/glassfish/deployment/autodeploy/AutoDeployService.java (working copy)
@@ -191,7 +191,7 @@
}
private void startAutoDeployer(int pollingIntervalInSeconds) {
- long pollingInterval = pollingIntervalInSeconds * 1000;
+ long pollingInterval = pollingIntervalInSeconds * 1000L;
autoDeployerTimer.schedule(
autoDeployerTimerTask = new TimerTask() {
@Override
Index: core/kernel/src/main/java/com/sun/enterprise/v3/server/DynamicReloadService.java
===================================================================
--- core/kernel/src/main/java/com/sun/enterprise/v3/server/DynamicReloadService.java (revision 31858)
+++ core/kernel/src/main/java/com/sun/enterprise/v3/server/DynamicReloadService.java (working copy)
@@ -146,7 +146,7 @@
}
private void start(int pollIntervalInSeconds) {
- long pollIntervalInMS = pollIntervalInSeconds * 1000;
+ long pollIntervalInMS = pollIntervalInSeconds * 1000L;
timer.schedule(
timerTask = new TimerTask() {
@Override
Index: extras/jmxcmd/src/main/java/com/sun/cli/jmxcmd/cmd/MonitorCmd.java
===================================================================
--- extras/jmxcmd/src/main/java/com/sun/cli/jmxcmd/cmd/MonitorCmd.java (revision 31858)
+++ extras/jmxcmd/src/main/java/com/sun/cli/jmxcmd/cmd/MonitorCmd.java (working copy)
@@ -904,7 +904,7 @@
{
try
{
- sleep(mInfo.mIntervalSeconds * 1000);
+ sleep(mInfo.mIntervalSeconds * 1000L);
}
catch (InterruptedException e)
{
Index: web/web-core/src/main/java/org/apache/catalina/servlets/WebdavServlet.java
===================================================================
--- web/web-core/src/main/java/org/apache/catalina/servlets/WebdavServlet.java (revision 31858)
+++ web/web-core/src/main/java/org/apache/catalina/servlets/WebdavServlet.java (working copy)
@@ -961,7 +961,7 @@
lockDuration = MAX_TIMEOUT;
}
}
- lock.expiresAt = System.currentTimeMillis() + (lockDuration * 1000);
+ lock.expiresAt = System.currentTimeMillis() + (lockDuration * 1000L);
int lockRequestType = LOCK_CREATION;
Index: web/web-glue/src/main/java/com/sun/enterprise/security/web/GlassFishSingleSignOn.java
===================================================================
--- web/web-glue/src/main/java/com/sun/enterprise/security/web/GlassFishSingleSignOn.java (revision 31858)
+++ web/web-glue/src/main/java/com/sun/enterprise/security/web/GlassFishSingleSignOn.java (working copy)
@@ -603,7 +603,7 @@
return;
}
- long tooOld = System.currentTimeMillis() - ssoMaxInactive * 1000;
+ long tooOld = System.currentTimeMillis() - ssoMaxInactive * 1000L;
//S1AS8 6155481 START
if (logger.isLoggable(Level.FINE)) {
logger.fine("SSO expiration started. Current entries: "
Index: web/web-glue/src/main/java/com/sun/appserv/web/cache/filter/HttpCacheEntry.java
===================================================================
--- web/web-glue/src/main/java/com/sun/appserv/web/cache/filter/HttpCacheEntry.java (revision 31858)
+++ web/web-glue/src/main/java/com/sun/appserv/web/cache/filter/HttpCacheEntry.java (working copy)
@@ -87,7 +87,7 @@
// timeout is relative to current time
this.expireTime = (timeout == -1) ? timeout :
- System.currentTimeMillis() + (timeout * 1000);
+ System.currentTimeMillis() + (timeout * 1000L);
}
/**
Index: web/web-glue/src/main/java/com/sun/appserv/web/taglibs/cache/CacheEntry.java
===================================================================
--- web/web-glue/src/main/java/com/sun/appserv/web/taglibs/cache/CacheEntry.java (revision 31858)
+++ web/web-glue/src/main/java/com/sun/appserv/web/taglibs/cache/CacheEntry.java (working copy)
@@ -81,7 +81,7 @@
public void computeExpireTime(int timeout) {
// timeout is relative to current time
this.expireTime = (timeout == NO_TIMEOUT) ? timeout :
- System.currentTimeMillis() + (timeout * 1000);
+ System.currentTimeMillis() + (timeout * 1000L);
}
/**
Index: transaction/jts/src/main/java/com/sun/jts/utils/RecoveryHooks/FailureInducer.java
===================================================================
--- transaction/jts/src/main/java/com/sun/jts/utils/RecoveryHooks/FailureInducer.java (revision 31858)
+++ transaction/jts/src/main/java/com/sun/jts/utils/RecoveryHooks/FailureInducer.java (working copy)
@@ -260,7 +260,7 @@
// wait for the stipulated duration
try {
- Thread.sleep(waitDuration.intValue() * 1000);
+ Thread.sleep(waitDuration.intValue() * 1000L);
} catch (Exception e) {}
}
}
Index: transaction/jts/src/main/java/com/sun/jts/CosTransactions/TimeoutManager.java
===================================================================
--- transaction/jts/src/main/java/com/sun/jts/CosTransactions/TimeoutManager.java (revision 31858)
+++ transaction/jts/src/main/java/com/sun/jts/CosTransactions/TimeoutManager.java (working copy)
@@ -193,7 +193,7 @@
}
timeoutInfo = new TimeoutInfo();
timeoutInfo.expireTime =
- new Date().getTime() + seconds * 1000;
+ new Date().getTime() + seconds * 1000L;
timeoutInfo.localTID = localTID;
timeoutInfo.timeoutType = timeoutType;
pendingTimeouts.put(localTID,timeoutInfo);
@@ -205,7 +205,7 @@
}
timeoutInfo = new TimeoutInfo();
timeoutInfo.expireTime =
- new Date().getTime() + seconds * 1000;
+ new Date().getTime() + seconds * 1000L;
timeoutInfo.localTID = localTID;
timeoutInfo.timeoutType = timeoutType;
indoubtTimeouts.put(localTID,timeoutInfo);
Index: transaction/jts/src/main/java/com/sun/jts/CosTransactions/DelegatedTimeoutManager.java
===================================================================
--- transaction/jts/src/main/java/com/sun/jts/CosTransactions/DelegatedTimeoutManager.java (revision 31858)
+++ transaction/jts/src/main/java/com/sun/jts/CosTransactions/DelegatedTimeoutManager.java (working copy)
@@ -174,7 +174,7 @@
}
timeoutInfo = new DelegatedTimeoutInfo();
timeoutInfo.expireTime =
- new Date().getTime() + seconds * 1000;
+ new Date().getTime() + seconds * 1000L;
timeoutInfo.localTID = localTID;
timeoutInfo.timeoutType = timeoutType;
pendingTimeouts.put(localTID,timeoutInfo);
@@ -186,7 +186,7 @@
}
timeoutInfo = new DelegatedTimeoutInfo();
timeoutInfo.expireTime =
- new Date().getTime() + seconds * 1000;
+ new Date().getTime() + seconds * 1000L;
timeoutInfo.localTID = localTID;
timeoutInfo.timeoutType = timeoutType;
indoubtTimeouts.put(localTID,timeoutInfo);
Index: transaction/jts/src/main/java/com/sun/jts/jta/TransactionServiceProperties.java
===================================================================
--- transaction/jts/src/main/java/com/sun/jts/jta/TransactionServiceProperties.java (revision 31858)
+++ transaction/jts/src/main/java/com/sun/jts/jta/TransactionServiceProperties.java (working copy)
@@ -246,7 +246,7 @@
int prevSize = 0;
try {
while(true) {
- Thread.sleep(interval*1000);
+ Thread.sleep(interval*1000L);
if (!RecoveryManager.isIncompleteTxRecoveryRequired()) {
if (_logger.isLoggable(Level.FINE))
_logger.log(Level.FINE, "Incomplete transaction recovery is "
Index: admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/pe/InstanceTimer.java
===================================================================
--- admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/pe/InstanceTimer.java (revision 31858)
+++ admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/pe/InstanceTimer.java (working copy)
@@ -59,12 +59,12 @@
startTime = System.currentTimeMillis();
try
{
- Thread.currentThread().sleep(startAfterSeconds * 1000);
+ Thread.sleep(startAfterSeconds * 1000L);
while (!timeOutReached() && !callBack.check())
{
try
{
- Thread.currentThread().sleep(1000);
+ Thread.sleep(1000);
computeTimeOut();
}
catch (InterruptedException ie)
Index: common/common-util/src/main/java/com/sun/enterprise/universal/xml/LocalStrings.properties
Index: jms/jms-core/src/main/java/com/sun/enterprise/connectors/jms/system/ActiveJmsResourceAdapter.java
===================================================================
--- jms/jms-core/src/main/java/com/sun/enterprise/connectors/jms/system/ActiveJmsResourceAdapter.java (revision 31858)
+++ jms/jms-core/src/main/java/com/sun/enterprise/connectors/jms/system/ActiveJmsResourceAdapter.java (working copy)
@@ -860,7 +860,7 @@
String specifiedTimeOut = jmsService.getInitTimeoutInSeconds();
if (specifiedTimeOut != null)
- timeout = Integer.parseInt(specifiedTimeOut) * 1000;
+ timeout = Integer.parseInt(specifiedTimeOut) * 1000L;
return timeout;
}
Index: ejb/ejb-container/src/main/java/com/sun/ejb/containers/ReadOnlyBeanContainer.java
===================================================================
--- ejb/ejb-container/src/main/java/com/sun/ejb/containers/ReadOnlyBeanContainer.java (revision 31858)
+++ ejb/ejb-container/src/main/java/com/sun/ejb/containers/ReadOnlyBeanContainer.java (working copy)
@@ -113,7 +113,7 @@
EjbEntityDescriptor ed = (EjbEntityDescriptor)desc;
refreshPeriodInMillis =
- ed.getIASEjbExtraDescriptors().getRefreshPeriodInSeconds() * 1000;
+ ed.getIASEjbExtraDescriptors().getRefreshPeriodInSeconds() * 1000L;
if( refreshPeriodInMillis > 0 ) {
long timerFrequency = 1;
@@ -139,7 +139,7 @@
Timer timer = ejbContainerUtilImpl.getTimer();
if (RELATIVE_TIME_CHECK_MODE) {
refreshTask = new CurrentTimeRefreshTask ();
- timer.scheduleAtFixedRate(refreshTask, timerFrequency*1000, timerFrequency*1000);
+ timer.scheduleAtFixedRate(refreshTask, timerFrequency*1000L, timerFrequency*1000L);
} else {
refreshTask = new RefreshTask();
timer.scheduleAtFixedRate(refreshTask, refreshPeriodInMillis,
@@ -155,7 +155,7 @@
// Create read-only bean cache
long idleTimeoutInMillis = (cacheProp.cacheIdleTimeoutInSeconds <= 0) ?
- -1 : (cacheProp.cacheIdleTimeoutInSeconds * 1000);
+ -1 : (cacheProp.cacheIdleTimeoutInSeconds * 1000L);
if( (cacheProp.maxCacheSize <= 0) && (idleTimeoutInMillis <= 0) ) {
robCache = new UnboundedEJBObjectCache(ejbDescriptor.getName());
Index: ejb/ejb-container/src/main/java/com/sun/ejb/containers/builder/StatefulContainerBuilder.java
===================================================================
--- ejb/ejb-container/src/main/java/com/sun/ejb/containers/builder/StatefulContainerBuilder.java (revision 31858)
+++ ejb/ejb-container/src/main/java/com/sun/ejb/containers/builder/StatefulContainerBuilder.java (working copy)
@@ -240,7 +240,7 @@
String ejbName = ejbDescriptor.getEjbClassName();
if (cacheProps.getCacheIdleTimeoutInSeconds() > 0) {
- long timeout = cacheProps.getCacheIdleTimeoutInSeconds() * 1000;
+ long timeout = cacheProps.getCacheIdleTimeoutInSeconds() * 1000L;
try {
sfsbContainer.invokePeriodically(timeout, timeout,
new CachePassivatorTask(ejbName, sessionCache, _logger));
@@ -258,7 +258,7 @@
}
if (cacheProps.getRemovalTimeoutInSeconds() > 0) {
- long timeout = cacheProps.getRemovalTimeoutInSeconds() * 1000;
+ long timeout = cacheProps.getRemovalTimeoutInSeconds() * 1000L;
try {
sfsbContainer.invokePeriodically(timeout, timeout,
new ExpiredSessionsRemovalTask(ejbName,
Index: ejb/ejb-container/src/main/java/com/sun/ejb/containers/util/cache/LruSessionCache.java
===================================================================
--- ejb/ejb-container/src/main/java/com/sun/ejb/containers/util/cache/LruSessionCache.java (revision 31858)
+++ ejb/ejb-container/src/main/java/com/sun/ejb/containers/util/cache/LruSessionCache.java (working copy)
@@ -126,7 +126,7 @@
(removalTime <= 0) ? 0 : removalTime;
if (cacheIdleTimeoutInSeconds > 0) {
- super.timeout = cacheIdleTimeoutInSeconds*1000;
+ super.timeout = cacheIdleTimeoutInSeconds*1000L;
}
removeIfIdle = (removalTimeoutInSeconds > 0)
@@ -155,7 +155,7 @@
StatefulEJBContext ctx = (StatefulEJBContext) item.value;
long idleThreshold =
- System.currentTimeMillis() - removalTimeoutInSeconds*1000;
+ System.currentTimeMillis() - removalTimeoutInSeconds*1000L;
if (ctx.getLastAccessTime() <= idleThreshold) {
container.passivateEJB(ctx);
return;
@@ -395,7 +395,7 @@
if (removeIfIdle) {
long idleThreshold = System.currentTimeMillis() -
- removalTimeoutInSeconds*1000;
+ removalTimeoutInSeconds*1000L;
//XXX: Avoid currentTimeMillis
if (ctx.getLastAccessTime() <= idleThreshold) {
if(_logger.isLoggable(Level.FINE)) {
@@ -615,7 +615,7 @@
int count = 0;
LruCacheItem item;
long currentTime = System.currentTimeMillis();
- long idleThresholdTime = currentTime - cacheIdleTimeoutInSeconds*1000;
+ long idleThresholdTime = currentTime - cacheIdleTimeoutInSeconds*1000L;
ArrayList victimList = new ArrayList();
synchronized (this) {
Index: ejb/ejb-container/src/main/java/com/sun/ejb/containers/util/pool/AbstractPool.java
===================================================================
--- ejb/ejb-container/src/main/java/com/sun/ejb/containers/util/pool/AbstractPool.java (revision 31858)
+++ ejb/ejb-container/src/main/java/com/sun/ejb/containers/util/pool/AbstractPool.java (working copy)
@@ -134,8 +134,8 @@
try {
this.poolTimerTask = new AbstractPoolTimerTask();
EjbContainerUtilImpl.getInstance().getTimer().scheduleAtFixedRate
- (poolTimerTask, idleTimeoutInSeconds*1000,
- idleTimeoutInSeconds*1000);
+ (poolTimerTask, idleTimeoutInSeconds*1000L,
+ idleTimeoutInSeconds*1000L);
} catch (Throwable th) {
_logger.log(Level.WARNING,
"[AbstractPool]: Could not add AbstractPoolTimerTask" +
Index: ejb/ejb-container/src/main/java/com/sun/ejb/containers/util/pool/NonBlockingPool.java
===================================================================
--- ejb/ejb-container/src/main/java/com/sun/ejb/containers/util/pool/NonBlockingPool.java (revision 31858)
+++ ejb/ejb-container/src/main/java/com/sun/ejb/containers/util/pool/NonBlockingPool.java (working copy)
@@ -122,8 +122,8 @@
try {
this.poolTimerTask = new PoolResizeTimerTask();
EjbContainerUtilImpl.getInstance().getTimer().scheduleAtFixedRate
- (poolTimerTask, idleTimeoutInSeconds*1000,
- idleTimeoutInSeconds*1000);
+ (poolTimerTask, idleTimeoutInSeconds*1000L,
+ idleTimeoutInSeconds*1000L);
if(_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE,
"[Pool-" + poolName + "]: Added PoolResizeTimerTask...");
@@ -456,7 +456,7 @@
(curSize > (steadyPoolSize + resizeQuantity) )
? resizeQuantity : (curSize - steadyPoolSize);
long allowedIdleTime = System.currentTimeMillis() -
- idleTimeoutInSeconds*1000;
+ idleTimeoutInSeconds*1000L;
if(_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE,
"[Pool-"+poolName+"]: Resize:: reducing "
Index: ejb/ejb-container/src/main/java/com/sun/ejb/containers/StatefulSessionContainer.java
===================================================================
--- ejb/ejb-container/src/main/java/com/sun/ejb/containers/StatefulSessionContainer.java (revision 31858)
+++ ejb/ejb-container/src/main/java/com/sun/ejb/containers/StatefulSessionContainer.java (working copy)
@@ -1485,7 +1485,7 @@
if ((context.existsInStore()) && (removalGracePeriodInSeconds > 0)) {
long now = System.currentTimeMillis();
- long threshold = now - (removalGracePeriodInSeconds * 1000);
+ long threshold = now - (removalGracePeriodInSeconds * 1000L);
if (context.getLastPersistedAt() <= threshold) {
try {
sfsbStoreManager.updateLastAccessTime(sessionKey, now);
Index: ejb/ejb-container/src/main/java/com/sun/ejb/containers/EntityContainer.java
===================================================================
--- ejb/ejb-container/src/main/java/com/sun/ejb/containers/EntityContainer.java (revision 31858)
+++ ejb/ejb-container/src/main/java/com/sun/ejb/containers/EntityContainer.java (working copy)
@@ -2624,7 +2624,7 @@
int cacheSize = cacheProp.maxCacheSize;
int numberOfVictimsToSelect = cacheProp.numberOfVictimsToSelect;
float loadFactor = DEFAULT_LOAD_FACTOR;
- idleTimeout = cacheProp.cacheIdleTimeoutInSeconds * 1000;
+ idleTimeout = cacheProp.cacheIdleTimeoutInSeconds * 1000L;
createReadyStore(cacheSize, numberOfVictimsToSelect, loadFactor,
idleTimeout);
Index: ejb/ejb-container/src/main/java/com/sun/ejb/containers/MessageBeanContainer.java
===================================================================
--- ejb/ejb-container/src/main/java/com/sun/ejb/containers/MessageBeanContainer.java (revision 31858)
+++ ejb/ejb-container/src/main/java/com/sun/ejb/containers/MessageBeanContainer.java (working copy)
@@ -843,7 +843,7 @@
_logger.log(Level.FINE, "[MDBContainer] "
+ "Going to wait for a maximum of " + timeout
+ " seconds.");
- task.wait(timeout * 1000);
+ task.wait(timeout * 1000L);
}
if (!task.isDone()) {
Index: ejb/ejb-container/src/main/java/com/sun/ejb/base/sfsb/store/FileStoreManager.java
===================================================================
--- ejb/ejb-container/src/main/java/com/sun/ejb/base/sfsb/store/FileStoreManager.java (revision 31858)
+++ ejb/ejb-container/src/main/java/com/sun/ejb/base/sfsb/store/FileStoreManager.java (working copy)
@@ -292,11 +295,14 @@
return 0;
}
long threshold = System.currentTimeMillis()
- - (passivationTimeoutInSeconds * 1000)
- - (gracePeriodInSeconds * 1000);
+ - (passivationTimeoutInSeconds * 1000L)
+ - (gracePeriodInSeconds * 1000L);
int expiredSessions = 0;
try {
String[] fileNames = baseDir.list();
Index: connectors/connectors-runtime/src/main/java/com/sun/enterprise/resource/pool/ConnectionPool.java
===================================================================
--- connectors/connectors-runtime/src/main/java/com/sun/enterprise/resource/pool/ConnectionPool.java (revision 31858)
+++ connectors/connectors-runtime/src/main/java/com/sun/enterprise/resource/pool/ConnectionPool.java (working copy)
@@ -163,7 +163,7 @@
private void setPoolConfiguration() throws PoolingException {
ConnectorConnectionPool poolResource = getPoolConfigurationFromJndi();
- idletime = Integer.parseInt(poolResource.getIdleTimeoutInSeconds()) * 1000;
+ idletime = Integer.parseInt(poolResource.getIdleTimeoutInSeconds()) * 1000L;
maxPoolSize = Integer.parseInt(poolResource.getMaxPoolSize());
steadyPoolSize = Integer.parseInt(poolResource.getSteadyPoolSize());
@@ -1285,14 +1285,14 @@
(poolResource.getConCreationRetryAttempts());
//Converting seconds to milliseconds as TimerTask will take input in milliseconds
conCreationRetryInterval_ =
- Integer.parseInt(poolResource.getConCreationRetryInterval()) * 1000;
+ Integer.parseInt(poolResource.getConCreationRetryInterval()) * 1000L;
connectionCreationRetry_ = connectionCreationRetryAttempts_ > 0;
validateAtmostPeriodInMilliSeconds_ =
- Integer.parseInt(poolResource.getValidateAtmostOncePeriod()) * 1000;
+ Integer.parseInt(poolResource.getValidateAtmostOncePeriod()) * 1000L;
boolean connectionLeakReclaim_ = poolResource.isConnectionReclaim();
long connectionLeakTimeoutInMilliSeconds_ = Integer.parseInt(
- poolResource.getConnectionLeakTracingTimeout()) * 1000;
+ poolResource.getConnectionLeakTracingTimeout()) * 1000L;
boolean connectionLeakTracing_ = connectionLeakTimeoutInMilliSeconds_ > 0;
if (leakDetector == null) {