From 062a9410f60faaa4a1c9cd7577088e37e33deaa8 Mon Sep 17 00:00:00 2001 From: Matt Bowersox Date: Thu, 13 Jan 2022 16:15:24 -0600 Subject: [PATCH] Fix timeout cast exception (#685) * 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 --- .../tools/gradle/tasks/DeployTask.groovy | 9 +++++++-- .../tools/gradle/tasks/DevTask.groovy | 19 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/DeployTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/DeployTask.groovy index 587055a8..40ce7fbd 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/DeployTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/DeployTask.groovy @@ -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 @@ -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 diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy index 60286124..e1a1b8ee 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; }