首页 > 解决方案 > Spring Cloud Task:任务参数中的多个空格导致 StringIndexOutOfBoundsException

问题描述

我正在使用SCDF Java DSL以编程方式在 Kubernetes 上启动任务。我注意到StringIndexOutOfBoundsException只要任务启动参数有多个空间,SCDF 服务器就会抛出一个。

例子 :

URI dataFlowUri = URI.create(dataFlowServerUri);
DataFlowOperations dataFlowOperations = new DataFlowTemplate(dataFlowUri);
Task task = Task.builder(dataFlowOperations).name(taskNameWithBatchIdInstanceId).definition(taskDefintion).description(taskDescription).build();

Map<String, String> taskLaunchProperties = new DeploymentPropertiesBuilder()
                    .put("deployer.task.kubernetes.limits.cpu", cpuLimit)
                    .put("deployer.task.kubernetes.limits.memory", memoryLimit)
                    .put("deployer.task.kubernetes.requests.cpu", cpuRequest)
                    .put("deployer.task.kubernetes.requests.memory", memoryRequest).build();

task.launch(taskLaunchProperties, Arrays.asList("inputArgument=ABC CDE FGH"));

我们可以看到上面的最后一行inputArguments=ABC CDE FGH作为参数传递。启动此任务会导致 SCDF 服务器上显示以下异常:

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1967) ~[na:1.8.0_281]
at org.springframework.cloud.deployer.spi.kubernetes.DefaultContainerFactory.lambda$createCommandArgs$0(DefaultContainerFactory.java:236) ~[spring-cloud-deployer-kubernetes-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]

在客户端,由于SCDF 服务器遇到,调用 会task.launch导致500 [no body]服务器响应。StringIndexOutOfBoundsException

经过大量试验,我意识到只有在任务输入参数中有多个空格时才会发生此异常。StringIndexOutOfBoundsException如果输入参数的空格少于 2 个并且在这种情况下不再看到,我可以启动任务。

task.launch(taskLaunchProperties, Arrays.asList("inputArgument=ABC CDE"));

问题:如何将具有多个空格的输入参数传递给 SCDF 任务?为什么 SCDF 不允许有多个空格的参数?这是一个错误吗?

标签: javaspringdslspring-cloud-dataflowspring-cloud-task

解决方案


推荐阅读