Skip to content

Commit

Permalink
Fix timeout cast exception (OpenLiberty#685)
Browse files Browse the repository at this point in the history
* Fix timeout cast exception

* Catch NumberFormatException for bad long value

* Update error message

* Update server parameter casts in DevTask

* Check for empty server.timeout value
  • Loading branch information
mattbsox authored and Jiwoo-Lim committed Jan 24, 2022
1 parent 1acc95c commit 062a941
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.gradle.api.logging.LogLevel
import org.gradle.api.tasks.TaskAction
import org.w3c.dom.Element

import java.lang.NumberFormatException
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import java.text.MessageFormat
Expand Down Expand Up @@ -642,8 +643,12 @@ class DeployTask extends AbstractServerTask {
}

long appTimeout = 30 * 1000
if (server.timeout != null && !server.timeout.isEmpty()) {
appTimeout = server.timeout * 1000
try {
if (server.timeout != null && !server.timeout.isEmpty()) {
appTimeout = Long.valueOf(server.timeout) * 1000
}
} catch (NumberFormatException nfe) {
throw new GradleException("The server.timeout parameter " + server.timeout + " could not be parsed into a long value. Ensure the value is formatted correctly.")
}

ServerTask serverTask = createServerTask(project, null) //Using a server task without an opertation to check logs for app start
Expand Down
19 changes: 12 additions & 7 deletions src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class DevTask extends AbstractFeatureTask {
@Option(option = 'libertyDebugPort', description = 'The debug port that you can attach a debugger to. The default value is 7777.')
void setLibertyDebugPort(String libertyDebugPort) {
try {
this.libertyDebugPort = libertyDebugPort.toInteger();
this.libertyDebugPort = Integer.valueOf(libertyDebugPort);
} catch (NumberFormatException e) {
logger.error(String.format("Unexpected value: %s for dev mode option libertyDebugPort. libertyDebugPort should be a valid integer.", libertyDebugPort));
throw e;
Expand All @@ -129,7 +129,7 @@ class DevTask extends AbstractFeatureTask {
@Option(option = 'compileWait', description = 'Time in seconds to wait before processing Java changes and deletions. The default value is 0.5 seconds.')
void setCompileWait(String compileWait) {
try {
this.compileWait = compileWait.toDouble();
this.compileWait = Double.valueOf(compileWait);
} catch (NumberFormatException e) {
logger.error(String.format("Unexpected value: %s for dev mode option compileWait. compileWait should be a valid number.", compileWait));
throw e;
Expand All @@ -141,7 +141,7 @@ class DevTask extends AbstractFeatureTask {
@Option(option = 'verifyAppStartTimeout', description = 'Maximum time to wait (in seconds) to verify that the application has started or updated before running tests. The default value is 30 seconds.')
void setVerifyAppStartTimeout(String verifyAppStartTimeout) {
try {
this.verifyAppStartTimeout = verifyAppStartTimeout.toInteger();
this.verifyAppStartTimeout = Integer.valueOf(verifyAppStartTimeout);
} catch (NumberFormatException e) {
logger.error(String.format("Unexpected value: %s for dev mode option verifyAppStartTimeout. verifyAppStartTimeout should be a valid integer.", verifyAppStartTimeout));
throw e;
Expand All @@ -153,7 +153,7 @@ class DevTask extends AbstractFeatureTask {
@Option(option = 'serverStartTimeout', description = 'Time in seconds to wait while verifying that the server has started. The default value is 90 seconds.')
void setServerStartTimeout(String serverStartTimeout) {
try {
this.serverStartTimeout = serverStartTimeout.toInteger();
this.serverStartTimeout = Integer.valueOf(serverStartTimeout);
} catch (NumberFormatException e) {
logger.error(String.format("Unexpected value: %s for dev mode option serverStartTimeout. serverStartTimeout should be a valid integer.", serverStartTimeout));
throw e;
Expand Down Expand Up @@ -230,7 +230,7 @@ class DevTask extends AbstractFeatureTask {
@Option(option = 'dockerBuildTimeout', description = 'Specifies the amount of time to wait (in seconds) for the completion of the Docker operation to build the image.')
void setDockerBuildTimeout(String inputValue) {
try {
this.dockerBuildTimeout = inputValue.toInteger();
this.dockerBuildTimeout = Integer.valueOf(inputValue);
} catch (NumberFormatException e) {
logger.error(String.format("Unexpected value: %s for dev mode option dockerBuildTimeout. dockerBuildTimeout should be a valid integer.", inputValue));
throw e;
Expand Down Expand Up @@ -924,8 +924,13 @@ class DevTask extends AbstractFeatureTask {
}

if (serverStartTimeout == null) {
if (server.timeout != null && server.timeout.isInteger()) {
serverStartTimeout = server.timeout.toInteger();
if (server.timeout != null && !server.timeout.isEmpty()) {
try {
serverStartTimeout = Integer.valueOf(server.timeout);
} catch (NumberFormatException e) {
logger.error(String.format("Unexpected value: %s for dev mode option server.timeout. server.timeout should be a valid integer.", server.timeout));
throw e;
}
} else {
serverStartTimeout = DEFAULT_SERVER_TIMEOUT;
}
Expand Down

0 comments on commit 062a941

Please sign in to comment.